feat(fe/api): expose quickshare api in the frontend dev mode
This commit is contained in:
parent
9172336d35
commit
e4940fca34
3 changed files with 65 additions and 6 deletions
42
src/client/web/src/components/api.ts
Normal file
42
src/client/web/src/components/api.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import { ICoreState } from "./core_state";
|
||||||
|
import { updater, Updater } from "./state_updater";
|
||||||
|
import { UploadEntry } from "../worker/interface";
|
||||||
|
|
||||||
|
export class QuickshareAPI {
|
||||||
|
private updater: Updater;
|
||||||
|
constructor() {
|
||||||
|
this.updater = updater();
|
||||||
|
}
|
||||||
|
initAll = async (params: URLSearchParams): Promise<string> => {
|
||||||
|
return this.updater.initAll(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
addUploadArray = (fileArray: Array<File>): string => {
|
||||||
|
return this.updater.addUploadArray(fileArray);
|
||||||
|
};
|
||||||
|
|
||||||
|
deleteUpload = async (filePath: string): Promise<string> => {
|
||||||
|
return await this.updater.deleteUpload(filePath);
|
||||||
|
};
|
||||||
|
|
||||||
|
listUploadArray = async (): Promise<Array<UploadEntry>> => {
|
||||||
|
return await this.updater.listUploadArray();
|
||||||
|
};
|
||||||
|
|
||||||
|
stopUploading = (filePath: string): string => {
|
||||||
|
return this.updater.stopUploading(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
self = async (): Promise<string> => {
|
||||||
|
return await this.updater.self();
|
||||||
|
};
|
||||||
|
|
||||||
|
getProps = (): ICoreState => {
|
||||||
|
return this.updater.props;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const api = new QuickshareAPI();
|
||||||
|
export const API = (): QuickshareAPI => {
|
||||||
|
return api;
|
||||||
|
};
|
|
@ -65,6 +65,20 @@ export class Updater {
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
listUploadArray = async (): Promise<Array<UploadEntry>> => {
|
||||||
|
const uploadsArray = new Array<UploadEntry>();
|
||||||
|
this.props.uploadingsInfo.uploadings.forEach((entry: UploadEntry) => {
|
||||||
|
uploadsArray.push(entry);
|
||||||
|
});
|
||||||
|
|
||||||
|
return uploadsArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
addUploadArray = (fileArray: Array<File>): string => {
|
||||||
|
const fileList = List<File>(fileArray);
|
||||||
|
return this.addUploads(fileList);
|
||||||
|
};
|
||||||
|
|
||||||
addUploads = (fileList: List<File>): string => {
|
addUploads = (fileList: List<File>): string => {
|
||||||
fileList.forEach((file) => {
|
fileList.forEach((file) => {
|
||||||
const filePath = getItemPath(
|
const filePath = getItemPath(
|
||||||
|
@ -340,7 +354,9 @@ export class Updater {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fails.size > 0) {
|
if (fails.size > 0) {
|
||||||
Env().alertMsg(`${this.props.msg.pkg.get("move.fail")}: ${fails.join(",\n")}`);
|
Env().alertMsg(
|
||||||
|
`${this.props.msg.pkg.get("move.fail")}: ${fails.join(",\n")}`
|
||||||
|
);
|
||||||
return errServer;
|
return errServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,19 +4,20 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||||
const dev = require("./webpack.dev.js");
|
const dev = require("./webpack.dev.js");
|
||||||
|
|
||||||
module.exports = merge(dev, {
|
module.exports = merge(dev, {
|
||||||
entry: "./src/app.tsx",
|
entry: ["./src/app.tsx", "./src/components/api.ts"],
|
||||||
context: `${__dirname}`,
|
context: `${__dirname}`,
|
||||||
output: {
|
output: {
|
||||||
globalObject: "this",
|
globalObject: "this",
|
||||||
path: `${__dirname}/../../../public/static`,
|
path: `${__dirname}/../../../public/static`,
|
||||||
chunkFilename: "[name].bundle.js",
|
chunkFilename: "[name].bundle.js",
|
||||||
filename: "[name].bundle.js"
|
filename: "[name].bundle.js",
|
||||||
|
library: "Q",
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: `${__dirname}/build/template/index.template.dev.html`,
|
template: `${__dirname}/build/template/index.template.dev.html`,
|
||||||
hash: true,
|
hash: true,
|
||||||
filename: `../index.html`
|
filename: `../index.html`,
|
||||||
})
|
}),
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue