feat(fe,be): enable short sharing urls, enable file info migration

This commit is contained in:
hexxa 2022-01-15 21:36:14 +08:00 committed by Hexxa
parent 18ee149956
commit 6dc8802752
5 changed files with 145 additions and 27 deletions

View file

@ -7,10 +7,12 @@ import {
ListUploadingsResp,
ListSharingsResp,
ListSharingIDsResp,
GetSharingDirResp,
} from "./";
const filePathQuery = "fp";
const listDirQuery = "dp";
const shareIDQuery = "sh";
// TODO: get timeout from server
function translateResp(resp: Response<any>): Response<any> {
@ -208,6 +210,16 @@ export class FilesClient extends BaseClient {
});
};
getSharingDir = (shareID: string): Promise<Response<GetSharingDirResp>> => {
return this.do({
method: "get",
url: `${this.url}/v1/fs/sharings/dirs`,
params: {
[shareIDQuery]: shareID,
},
});
};
generateHash = (filePath: string): Promise<Response> => {
return this.do({
method: "post",

View file

@ -5,6 +5,7 @@ import {
ListUploadingsResp,
ListSharingsResp,
ListSharingIDsResp,
GetSharingDirResp,
} from "./";
export interface FilesClientResps {
@ -26,6 +27,7 @@ export interface FilesClientResps {
deleteSharingMockResp?: Response;
listSharingsMockResp?: Response<ListSharingsResp>;
listSharingIDsMockResp?: Response<ListSharingIDsResp>;
getSharingDirMockResp?: Response<GetSharingDirResp>;
isSharingMockResp?: Response;
generateHashMockResp?: Response;
downloadMockResp: Response;
@ -144,6 +146,13 @@ export const resps = {
IDs: sharingIDs,
},
},
getSharingDirMockResp: {
status: 200,
statusText: "",
data: {
sharingDir: "/admin/sharing",
},
},
isSharingMockResp: { status: 200, statusText: "", data: {} },
generateHashMockResp: { status: 200, statusText: "", data: {} },
downloadMockResp: {
@ -231,10 +240,15 @@ export class MockFilesClient {
listSharings = (): Promise<Response<ListSharingsResp>> => {
return this.wrapPromise(this.resps.listSharingsMockResp);
};
listSharingIDs = (): Promise<Response<ListSharingIDsResp>> => {
return this.wrapPromise(this.resps.listSharingIDsMockResp);
};
getSharingDir = (): Promise<Response<GetSharingDirResp>> => {
return this.wrapPromise(this.resps.getSharingDirMockResp);
}
isSharing = (dirPath: string): Promise<Response> => {
return this.wrapPromise(this.resps.isSharingMockResp);
};

View file

@ -84,6 +84,10 @@ export interface ListSharingIDsResp {
IDs: Map<string, string>;
}
export interface GetSharingDirResp {
sharingDir: string;
}
export interface ClientConfigMsg {
clientCfg: ClientConfig;
}
@ -142,6 +146,7 @@ export interface IFilesClient {
isSharing: (dirPath: string) => Promise<Response>;
listSharings: () => Promise<Response<ListSharingsResp>>;
listSharingIDs: () => Promise<Response<ListSharingIDsResp>>;
getSharingDir: (shareID: string) => Promise<Response<GetSharingDirResp>>;
generateHash: (filePath: string) => Promise<Response>;
download: (url: string) => Promise<Response>;
}

View file

@ -127,13 +127,7 @@ export class Updater {
if (resp.status !== 200) {
return errServer;
}
// transform from built-in map to immutable map
let sharings = Map<string, string>();
resp.data.IDs.forEach((shareID: string, dirPath: string) => {
sharings = sharings.set(dirPath, shareID);
});
this.props.sharingsInfo.sharings = sharings;
this.props.sharingsInfo.sharings = Map<string, string>(resp.data.IDs);
return "";
};
@ -464,8 +458,28 @@ export class Updater {
return "";
};
getParamMap = async (params: URLSearchParams): Promise<Map<string, string>> => {
let paramMap = Map<string, string>();
paramMap = paramMap.set("sh", "");
paramMap = paramMap.set("dir", "");
let shareID = params.get("sh");
if (shareID != null && shareID !== "") {
paramMap = paramMap.set("sh", shareID);
const resp = await this.filesClient.getSharingDir(shareID)
if (resp.status === 200) {
paramMap = paramMap.set("dir", resp.data.sharingDir);
}
} else {
paramMap = paramMap.set("dir", params.get("dir"));
}
return paramMap;
};
initCwd = async (params: URLSearchParams): Promise<string> => {
const dir = params.get("dir");
const paramMap = await this.getParamMap(params)
const dir = paramMap.get("dir", "");
if (dir != null && dir !== "") {
// in sharing mode