Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/filesystem/baidu/baidu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AuthVerify } from "../auth";
import type FileSystem from "../filesystem";
import type { File, FileReader, FileWriter } from "../filesystem";
import type { FileInfo, FileReader, FileWriter } from "../filesystem";
import { joinPath } from "../utils";
import { BaiduFileReader, BaiduFileWriter } from "./rw";

Expand All @@ -20,7 +20,7 @@ export default class BaiduFileSystem implements FileSystem {
return this.list().then();
}

async open(file: File): Promise<FileReader> {
async open(file: FileInfo): Promise<FileReader> {
// 获取fsid
return new BaiduFileReader(this, file);
}
Expand Down Expand Up @@ -126,8 +126,8 @@ export default class BaiduFileSystem implements FileSystem {
});
}

async list(): Promise<File[]> {
const list: File[] = [];
async list(): Promise<FileInfo[]> {
const list: FileInfo[] = [];
let start = 0;
const limit = 200;
// 防御性:限制最大分页轮询次数,避免在 API 异常返回时出现无限循环
Expand Down
6 changes: 3 additions & 3 deletions packages/filesystem/baidu/rw.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { File, FileReader, FileWriter } from "../filesystem";
import type { FileInfo, FileReader, FileWriter } from "../filesystem";
import { calculateMd5, md5OfText } from "@App/pkg/utils/crypto";
import type BaiduFileSystem from "./baidu";

export class BaiduFileReader implements FileReader {
file: File;
file: FileInfo;

fs: BaiduFileSystem;

constructor(fs: BaiduFileSystem, file: File) {
constructor(fs: BaiduFileSystem, file: FileInfo) {
this.fs = fs;
this.file = file;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/filesystem/dropbox/dropbox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AuthVerify } from "../auth";
import type FileSystem from "../filesystem";
import type { File, FileReader, FileWriter } from "../filesystem";
import type { FileInfo, FileReader, FileWriter } from "../filesystem";
import { joinPath } from "../utils";
import { DropboxFileReader, DropboxFileWriter } from "./rw";

Expand All @@ -24,7 +24,7 @@ export default class DropboxFileSystem implements FileSystem {
return this.list().then();
}

open(file: File): Promise<FileReader> {
open(file: FileInfo): Promise<FileReader> {
return Promise.resolve(new DropboxFileReader(this, file));
}

Expand Down Expand Up @@ -138,7 +138,7 @@ export default class DropboxFileSystem implements FileSystem {
this.clearRelatedCache(fullPath);
}

async list(): Promise<File[]> {
async list(): Promise<FileInfo[]> {
let folderPath = this.path;

// Dropbox API 需要空字符串来表示根目录
Expand All @@ -162,7 +162,7 @@ export default class DropboxFileSystem implements FileSystem {
throw e;
});

const list: File[] = [];
const list: FileInfo[] = [];

const MAX_ITERATIONS = 100;
let iterationCount = 0;
Expand Down
6 changes: 3 additions & 3 deletions packages/filesystem/dropbox/rw.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { File, FileReader, FileWriter } from "../filesystem";
import type { FileInfo, FileReader, FileWriter } from "../filesystem";
import { joinPath } from "../utils";
import type DropboxFileSystem from "./dropbox";

export class DropboxFileReader implements FileReader {
file: File;
file: FileInfo;

fs: DropboxFileSystem;

constructor(fs: DropboxFileSystem, file: File) {
constructor(fs: DropboxFileSystem, file: FileInfo) {
this.fs = fs;
this.file = file;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/filesystem/filesystem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface File {
export interface FileInfo {
fsid?: number;
// 文件名
name: string;
Expand Down Expand Up @@ -32,7 +32,7 @@ export default interface FileSystem {
// 授权验证
verify(): Promise<void>;
// 打开文件
open(file: File): Promise<FileReader>;
open(file: FileInfo): Promise<FileReader>;
// 打开目录
openDir(path: string): Promise<FileSystem>;
// 创建文件
Expand All @@ -42,7 +42,7 @@ export default interface FileSystem {
// 删除文件
delete(path: string): Promise<void>;
// 文件列表
list(): Promise<File[]>;
list(): Promise<FileInfo[]>;
// getDirUrl 获取目录的url
getDirUrl(): Promise<string>;
}
8 changes: 4 additions & 4 deletions packages/filesystem/googledrive/googledrive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AuthVerify } from "../auth";
import type FileSystem from "../filesystem";
import type { File, FileReader, FileWriter } from "../filesystem";
import type { FileInfo, FileReader, FileWriter } from "../filesystem";
import { joinPath } from "../utils";
import { GoogleDriveFileReader, GoogleDriveFileWriter } from "./rw";

Expand All @@ -23,7 +23,7 @@ export default class GoogleDriveFileSystem implements FileSystem {
return this.list().then();
}

open(file: File): Promise<FileReader> {
open(file: FileInfo): Promise<FileReader> {
return Promise.resolve(new GoogleDriveFileReader(this, file));
}

Expand Down Expand Up @@ -208,7 +208,7 @@ export default class GoogleDriveFileSystem implements FileSystem {

return parentId;
}
async list(): Promise<File[]> {
async list(): Promise<FileInfo[]> {
let folderId = "appDataFolder";

// 获取当前目录的ID
Expand All @@ -221,7 +221,7 @@ export default class GoogleDriveFileSystem implements FileSystem {
}

// 列出目录内容,处理分页
const list: File[] = [];
const list: FileInfo[] = [];
let pageToken: string | undefined = undefined;

const query = `'${folderId}' in parents and trashed=false`;
Expand Down
6 changes: 3 additions & 3 deletions packages/filesystem/googledrive/rw.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { File, FileReader, FileWriter } from "../filesystem";
import type { FileInfo, FileReader, FileWriter } from "../filesystem";
import { joinPath } from "../utils";
import type GoogleDriveFileSystem from "./googledrive";

export class GoogleDriveFileReader implements FileReader {
file: File;
file: FileInfo;

fs: GoogleDriveFileSystem;

constructor(fs: GoogleDriveFileSystem, file: File) {
constructor(fs: GoogleDriveFileSystem, file: FileInfo) {
this.fs = fs;
this.file = file;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/filesystem/limiter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type FileSystem from "./filesystem";
import type { File, FileReader, FileWriter } from "./filesystem";
import type { FileInfo, FileReader, FileWriter } from "./filesystem";

/**
* 速率限制器
Expand Down Expand Up @@ -86,7 +86,7 @@ export default class LimiterFileSystem implements FileSystem {
return this.limiter.execute(() => this.fs.verify());
}

async open(file: File): Promise<FileReader> {
async open(file: FileInfo): Promise<FileReader> {
return this.limiter.execute(async () => {
const reader = await this.fs.open(file);
return {
Expand Down Expand Up @@ -119,7 +119,7 @@ export default class LimiterFileSystem implements FileSystem {
return this.limiter.execute(() => this.fs.delete(path));
}

list(): Promise<File[]> {
list(): Promise<FileInfo[]> {
return this.limiter.execute(() => this.fs.list());
}

Expand Down
8 changes: 4 additions & 4 deletions packages/filesystem/onedrive/onedrive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AuthVerify } from "../auth";
import type { File, FileReader, FileWriter } from "../filesystem";
import type { FileInfo, FileReader, FileWriter } from "../filesystem";
import type FileSystem from "../filesystem";
import { joinPath } from "../utils";
import { OneDriveFileReader, OneDriveFileWriter } from "./rw";
Expand All @@ -20,7 +20,7 @@ export default class OneDriveFileSystem implements FileSystem {
return this.list().then();
}

async open(file: File): Promise<FileReader> {
async open(file: FileInfo): Promise<FileReader> {
return new OneDriveFileReader(this, file);
}

Expand Down Expand Up @@ -118,15 +118,15 @@ export default class OneDriveFileSystem implements FileSystem {
return resp;
}

async list(): Promise<File[]> {
async list(): Promise<FileInfo[]> {
let { path } = this;
if (path === "/") {
path = "";
} else {
path = `:${path}:`;
}

const list: File[] = [];
const list: FileInfo[] = [];
let nextLink: string | undefined = `https://graph.microsoft.com/v1.0/me/drive/special/approot${path}/children`;
let iterationCount = 0;
const MAX_ITERATIONS = 100;
Expand Down
6 changes: 3 additions & 3 deletions packages/filesystem/onedrive/rw.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { calculateMd5, md5OfText } from "@App/pkg/utils/crypto";
import type { File, FileReader, FileWriter } from "../filesystem";
import type { FileInfo, FileReader, FileWriter } from "../filesystem";
import { joinPath } from "../utils";
import type OneDriveFileSystem from "./onedrive";

export class OneDriveFileReader implements FileReader {
file: File;
file: FileInfo;

fs: OneDriveFileSystem;

constructor(fs: OneDriveFileSystem, file: File) {
constructor(fs: OneDriveFileSystem, file: FileInfo) {
this.fs = fs;
this.file = file;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/filesystem/webdav/webdav.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AuthType, FileStat, WebDAVClient } from "webdav";
import { createClient } from "webdav";
import type FileSystem from "../filesystem";
import type { File, FileReader, FileWriter } from "../filesystem";
import type { FileInfo, FileReader, FileWriter } from "../filesystem";
import { joinPath } from "../utils";
import { WebDAVFileReader, WebDAVFileWriter } from "./rw";
import { WarpTokenError } from "../error";
Expand Down Expand Up @@ -39,7 +39,7 @@ export default class WebDAVFileSystem implements FileSystem {
}
}

async open(file: File): Promise<FileReader> {
async open(file: FileInfo): Promise<FileReader> {
return new WebDAVFileReader(this.client, joinPath(file.path, file.name));
}

Expand Down Expand Up @@ -67,9 +67,9 @@ export default class WebDAVFileSystem implements FileSystem {
return this.client.deleteFile(joinPath(this.basePath, path));
}

async list(): Promise<File[]> {
async list(): Promise<FileInfo[]> {
const dir = (await this.client.getDirectoryContents(this.basePath)) as FileStat[];
const ret: File[] = [];
const ret: FileInfo[] = [];
for (const item of dir) {
if (item.type !== "file") {
continue;
Expand Down
8 changes: 4 additions & 4 deletions packages/filesystem/zip/zip.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type JSZip from "jszip";
import type { File, FileReader, FileWriter } from "@Packages/filesystem/filesystem";
import type { FileInfo, FileReader, FileWriter } from "@Packages/filesystem/filesystem";
import type FileSystem from "@Packages/filesystem/filesystem";
import { ZipFileReader, ZipFileWriter } from "./rw";

Expand All @@ -18,7 +18,7 @@ export default class ZipFileSystem implements FileSystem {
// do nothing
}

async open(info: File): Promise<FileReader> {
async open(info: FileInfo): Promise<FileReader> {
const path = info.name;
const file = this.zip.file(path);
if (file) {
Expand All @@ -43,8 +43,8 @@ export default class ZipFileSystem implements FileSystem {
this.zip.remove(path);
}

async list(): Promise<File[]> {
const files: File[] = [];
async list(): Promise<FileInfo[]> {
const files: FileInfo[] = [];
for (const [filename, details] of Object.entries(this.zip.files)) {
const time = details.date.getTime();
files.push({
Expand Down
14 changes: 4 additions & 10 deletions src/app/service/service_worker/synchronize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Resource } from "@App/app/repo/resource";
import { type Script, SCRIPT_STATUS_DISABLE, SCRIPT_STATUS_ENABLE, type ScriptDAO } from "@App/app/repo/scripts";
import BackupExport from "@App/pkg/backup/export";
import type { BackupData, ResourceBackup, ScriptBackupData, ScriptOptions, ValueStorage } from "@App/pkg/backup/struct";
import type { File } from "@Packages/filesystem/filesystem";
import type { FileInfo } from "@Packages/filesystem/filesystem";
import type FileSystem from "@Packages/filesystem/filesystem";
import ZipFileSystem from "@Packages/filesystem/zip/zip";
import FileSystemFactory, { type FileSystemType } from "@Packages/filesystem/factory";
Expand All @@ -30,8 +30,8 @@ import i18n, { i18nName } from "@App/locales/locales";
// type SynchronizeTarget = "local";

type SyncFiles = {
script: File;
meta: File;
script: FileInfo;
meta: FileInfo;
};

type SyncMeta = {
Expand Down Expand Up @@ -329,13 +329,7 @@ export class SynchronizeService {
// 获取文件列表
const list = await fs.list();
// 根据文件名生成一个map
const uuidMap = new Map<
string,
{
script?: File;
meta?: File;
}
>();
const uuidMap = new Map<string, Partial<SyncFiles>>();
Copy link
Collaborator Author

@cyfung1031 cyfung1031 Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注:这里直接改成了 Partial<SyncFiles>

// 储存文件摘要,用于检测文件是否有变化
const fileDigestMap =
((await this.storage.get("file_digest")) as {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/options/routes/Tools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { IconQuestionCircleFill } from "@arco-design/web-react/icon";
import type { RefInputType } from "@arco-design/web-react/es/Input/interface";
import { useTranslation } from "react-i18next";
import FileSystemFactory from "@Packages/filesystem/factory";
import type { File, FileReader } from "@Packages/filesystem/filesystem";
import type { FileInfo, FileReader } from "@Packages/filesystem/filesystem";
import { message } from "@App/pages/store/global";
import { synchronizeClient } from "@App/pages/store/features/script";
import { SystemClient } from "@App/app/service/service_worker/client";
Expand All @@ -30,7 +30,7 @@ function Tools() {
const [modal, contextHolder] = Modal.useModal();
const [loading, setLoading] = useState<{ [key: string]: boolean }>({});
const fileRef = useRef<HTMLInputElement>(null);
const [backupFileList, setBackupFileList] = useState<File[]>([]);
const [backupFileList, setBackupFileList] = useState<FileInfo[]>([]);
const vscodeRef = useRef<RefInputType>(null);
const { t } = useTranslation();
const [backup, setBackup, submitBackup] = useSystemConfig("backup");
Expand Down Expand Up @@ -191,7 +191,7 @@ function Tools() {
<List
bordered={false}
dataSource={backupFileList}
render={(item: File) => (
render={(item: FileInfo) => (
<List.Item key={`${item.name}_${item.updatetime}`}>
<List.Item.Meta title={item.name} description={formatUnixTime(item.updatetime / 1000)} />
<Space className="w-full justify-end">
Expand Down
Loading
Loading