feat(fe/api): expose delete api in fe

This commit is contained in:
hexxa 2022-04-03 17:19:35 +08:00 committed by Hexxa
parent 0e77cfe335
commit 79ccda2a67
2 changed files with 26 additions and 2 deletions

View file

@ -1,6 +1,7 @@
import { ICoreState } from "./core_state"; import { ICoreState } from "./core_state";
import { updater, Updater } from "./state_updater"; import { updater, Updater } from "./state_updater";
import { UploadEntry } from "../worker/interface"; import { UploadEntry } from "../worker/interface";
import { MetadataResp } from "../client";
export class QuickshareAPI { export class QuickshareAPI {
private updater: Updater; private updater: Updater;
@ -9,7 +10,7 @@ export class QuickshareAPI {
} }
initAll = async (params: URLSearchParams): Promise<string> => { initAll = async (params: URLSearchParams): Promise<string> => {
return this.updater.initAll(params); return this.updater.initAll(params);
} };
addUploadArray = (fileArray: Array<File>): string => { addUploadArray = (fileArray: Array<File>): string => {
return this.updater.addUploadArray(fileArray); return this.updater.addUploadArray(fileArray);
@ -25,7 +26,7 @@ export class QuickshareAPI {
stopUploading = (filePath: string): string => { stopUploading = (filePath: string): string => {
return this.updater.stopUploading(filePath); return this.updater.stopUploading(filePath);
} };
self = async (): Promise<string> => { self = async (): Promise<string> => {
return await this.updater.self(); return await this.updater.self();
@ -34,6 +35,14 @@ export class QuickshareAPI {
getProps = (): ICoreState => { getProps = (): ICoreState => {
return this.updater.props; return this.updater.props;
}; };
delete = async (
dir: string,
items: Array<MetadataResp>,
selectedItems: Array<string>
): Promise<string> => {
return await this.updater.delete2(dir, items, selectedItems);
};
} }
const api = new QuickshareAPI(); const api = new QuickshareAPI();

View file

@ -221,6 +221,21 @@ export class Updater {
return ""; return "";
}; };
delete2 = async (
dir: string,
items: Array<MetadataResp>,
selectedItems: Array<string>
): Promise<string> => {
const dirParts = List(dir.split("/")).filter((part) => part !== "");
const itemsList = List(items);
let selectedItemsMap = Map<string, boolean>();
selectedItems.forEach((item) => {
selectedItemsMap = selectedItemsMap.set(item, true);
});
return this.delete(dirParts, itemsList, selectedItemsMap);
};
delete = async ( delete = async (
dirParts: List<string>, dirParts: List<string>,
items: List<MetadataResp>, items: List<MetadataResp>,