File size: 4,438 Bytes
0070fce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
import { Dict } from '@/util'
import type { FileNodeInfo } from './files'
import { axiosInst } from './index'
import { PageCursor } from 'vue3-ts-util'
export interface Tag {
name: string
id: number | string
display_name: string | null
type: string
color: string
count: number
}
export type DataBaseBasicInfo = {
img_count: number
tags: Tag[]
expired: boolean
expired_dirs: string[]
}
export const getDbBasicInfo = async () => {
const resp = await axiosInst.value.get('/db/basic_info')
return resp.data as DataBaseBasicInfo
}
export const getExpiredDirs = async () => {
const resp = await axiosInst.value.get('/db/expired_dirs')
return resp.data as Pick<DataBaseBasicInfo, 'expired' | 'expired_dirs'>
}
export const updateImageData = async () => {
await axiosInst.value.post('/db/update_image_data', {}, { timeout: Infinity })
}
export const updateTag = async (tag: Tag) => {
await axiosInst.value.post('/db/update_tag', tag)
}
export type TagId = number | string
export interface MatchImageByTagsReq {
folder_paths_str?: string
and_tags: TagId[]
or_tags: TagId[]
not_tags: TagId[]
}
export const getImagesByTags = async (req: MatchImageByTagsReq, cursor: string) => {
const resp = await axiosInst.value.post('/db/match_images_by_tags', {
...req,
folder_paths: (req.folder_paths_str ?? '').split(/,|\n/).map(v => v.trim()).filter(v => v),
cursor
})
return resp.data as {
files: FileNodeInfo[],
cursor: PageCursor
}
}
export const addCustomTag = async (req: { tag_name: string }) => {
const resp = await axiosInst.value.post('/db/add_custom_tag', req)
return resp.data as Tag
}
export const toggleCustomTagToImg = async (req: { tag_id: TagId; img_path: string }) => {
const resp = await axiosInst.value.post('/db/toggle_custom_tag_to_img', req)
return resp.data as { is_remove: boolean }
}
export const removeCustomTag = async (req: { tag_id: TagId }) => {
await axiosInst.value.post('/db/remove_custom_tag', req)
}
export const removeCustomTagToImg = async (req: { tag_id: TagId; img_id: TagId }) => {
await axiosInst.value.post('/db/add_custom_tag_from_img', req)
}
export const getImageSelectedCustomTag = async (path: string) => {
const resp = await axiosInst.value.get('/db/img_selected_custom_tag', { params: { path } })
return resp.data as Tag[]
}
export const getRandomImages = async () => {
const resp = await axiosInst.value.get('/db/random_images')
return resp.data as FileNodeInfo[]
}
export interface SearchBySubstrReq {
surstr: string;
cursor: string;
regexp: string;
path_only?: boolean;
folder_paths?: string[];
size?: number;
}
export const getImagesBySubstr = async (req: SearchBySubstrReq) => {
const resp = await axiosInst.value.post('/db/search_by_substr', req)
return resp.data as {
files: FileNodeInfo[],
cursor: PageCursor
}
}
const extraPaths = '/db/extra_paths'
export type ExtraPathType = 'scanned' | 'walk' | 'cli_access_only' | '' | 'scanned-fixed'
export interface ExtraPathModel {
path: string
alias?: string
types: ExtraPathType[]
}
export const getExtraPath = async () => {
const resp = await axiosInst.value.get(extraPaths)
return resp.data as ExtraPathModel[]
}
export const addExtraPath = async (model: ExtraPathModel) => {
await axiosInst.value.post(extraPaths, model)
}
export const removeExtraPath = async (req: ExtraPathModel) => {
await axiosInst.value.delete(extraPaths, { data: req })
}
export interface ExtraPathAliasModel {
path: string
alias: string
}
export const aliasExtraPath = async (model: ExtraPathAliasModel) => {
await axiosInst.value.post('/db/alias_extra_path', model)
}
export const batchGetTagsByPath = async (paths: string[]) => {
const resp = await axiosInst.value.post('/db/get_image_tags', { paths })
return resp.data as Dict<Tag[]>
}
export const rebuildImageIndex = () => axiosInst.value.post('/db/rebuild_index')
export interface BatchUpdateTagParams {
img_paths: string[]
action: 'add' | 'remove'
tag_id: number
}
export const batchUpdateImageTag = (data: BatchUpdateTagParams) => {
return axiosInst.value.post('/db/batch_update_image_tag', data)
}
export interface RenameFileParams {
path: string
name: string
}
export const renameFile = async (data: RenameFileParams) => {
const resp = await axiosInst.value.post('/db/rename', data)
return resp.data as Promise<{ new_path:string }>
} |