add check sync

This commit is contained in:
2025-05-16 02:54:30 +08:00
parent aab0662fbc
commit 4e007d48a4
7 changed files with 186 additions and 18 deletions

View File

@@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs';
import { storage, baseURL } from '../query.ts';
import { chalk } from '../chalk.ts';
import { Result } from '@kevisual/query';
type DownloadTask = {
downloadPath: string;
downloadUrl: string;
@@ -194,3 +194,35 @@ export const uninstallApp = async (app: Partial<Package>, opts: UninstallAppOpts
};
}
};
export type AiList = {
name?: string;
lastModified?: string;
etag?: string;
size?: number;
path: string;
pathname?: string;
url?: string;
};
export const fetchAiList = async (url: string, opts?: { recursive: boolean }): Promise<Result<AiList[]>> => {
const token = process.env.KEVISUAL_TOKEN || storage.getItem('token');
const _url = new URL(url);
const dir = _url.searchParams.get('dir');
if (!dir) {
_url.searchParams.set('dir', 'true');
}
if (opts?.recursive) {
_url.searchParams.set('recursive', 'true');
}
if (!_url.pathname.endsWith('/')) {
_url.pathname += '/';
}
const res = await fetch(_url.toString(), {
method: 'GET',
headers: {
Authorization: 'Bearer ' + token,
},
});
const data = await res.json();
return data;
};