|
@@ -1,26 +1,26 @@
|
|
-import axios from "axios";
|
|
|
|
|
|
+import axios from 'axios';
|
|
|
|
|
|
export async function upload(
|
|
export async function upload(
|
|
blob: Blob,
|
|
blob: Blob,
|
|
shared = false,
|
|
shared = false,
|
|
- filename = "thumb.png",
|
|
|
|
- directory = "/2D/缩略图"
|
|
|
|
|
|
+ filename = 'thumb.png',
|
|
|
|
+ directory = '/2D/缩略图'
|
|
) {
|
|
) {
|
|
const form = new FormData();
|
|
const form = new FormData();
|
|
- form.append("filename", filename);
|
|
|
|
- form.append("directory", directory);
|
|
|
|
- form.append("public", shared + "");
|
|
|
|
- form.append("file", blob);
|
|
|
|
- const ret: any = await axios.post("/api/image/upload", form);
|
|
|
|
- if (ret.error) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ form.append('filename', filename);
|
|
|
|
+ form.append('directory', directory);
|
|
|
|
+ form.append('public', shared + '');
|
|
|
|
+ form.append('file', blob);
|
|
|
|
+ const ret: any = await axios.post('/api/image/upload', form);
|
|
|
|
+ if (!ret) {
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
export async function delImage(image: string) {
|
|
export async function delImage(image: string) {
|
|
- const ret: any = await axios.delete("/api" + image);
|
|
|
|
|
|
+ const ret: any = await axios.delete('/api' + image);
|
|
if (ret.error) {
|
|
if (ret.error) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -29,20 +29,20 @@ export async function delImage(image: string) {
|
|
}
|
|
}
|
|
|
|
|
|
export async function addImage(image: string) {
|
|
export async function addImage(image: string) {
|
|
- const ret: any = await axios.post("/api/user/image", { image });
|
|
|
|
|
|
+ const ret: any = await axios.post('/api/user/image', { image });
|
|
if (ret.error) {
|
|
if (ret.error) {
|
|
- return "";
|
|
|
|
|
|
+ return '';
|
|
}
|
|
}
|
|
|
|
|
|
return ret.id;
|
|
return ret.id;
|
|
}
|
|
}
|
|
|
|
|
|
export function filename(str: string) {
|
|
export function filename(str: string) {
|
|
- const i = str.lastIndexOf(".");
|
|
|
|
|
|
+ const i = str.lastIndexOf('.');
|
|
return str.substring(0, i);
|
|
return str.substring(0, i);
|
|
}
|
|
}
|
|
|
|
|
|
-const units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
|
|
|
|
+const units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
export function formatBytes(size: number) {
|
|
export function formatBytes(size: number) {
|
|
let l = 0;
|
|
let l = 0;
|
|
let n = size / 1024;
|
|
let n = size / 1024;
|
|
@@ -51,7 +51,7 @@ export function formatBytes(size: number) {
|
|
n = n / 1024;
|
|
n = n / 1024;
|
|
}
|
|
}
|
|
|
|
|
|
- return Math.round(n * 100) / 100 + " " + units[l];
|
|
|
|
|
|
+ return Math.round(n * 100) / 100 + ' ' + units[l];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -71,7 +71,7 @@ export async function readFile(file: Blob) {
|
|
}
|
|
}
|
|
|
|
|
|
export function dataURLtoBlob(base64: string) {
|
|
export function dataURLtoBlob(base64: string) {
|
|
- let arr: any = base64.split(","),
|
|
|
|
|
|
+ let arr: any = base64.split(','),
|
|
mime = arr[0].match(/:(.*?);/)[1],
|
|
mime = arr[0].match(/:(.*?);/)[1],
|
|
bstr = atob(arr[1]),
|
|
bstr = atob(arr[1]),
|
|
n = bstr.length,
|
|
n = bstr.length,
|
|
@@ -87,12 +87,12 @@ export function dataURLtoBlob(base64: string) {
|
|
* @param img 图片
|
|
* @param img 图片
|
|
*/
|
|
*/
|
|
export function saveToBlob(img: HTMLImageElement): Blob {
|
|
export function saveToBlob(img: HTMLImageElement): Blob {
|
|
- const canvas: HTMLCanvasElement = document.createElement("canvas");
|
|
|
|
- canvas.setAttribute("origin-clean", "false");
|
|
|
|
|
|
+ const canvas: HTMLCanvasElement = document.createElement('canvas');
|
|
|
|
+ canvas.setAttribute('origin-clean', 'false');
|
|
canvas.width = img.width;
|
|
canvas.width = img.width;
|
|
canvas.height = img.height;
|
|
canvas.height = img.height;
|
|
|
|
|
|
- const context: any = canvas.getContext("2d");
|
|
|
|
|
|
+ const context: any = canvas.getContext('2d');
|
|
context.filter = window.getComputedStyle(img).filter;
|
|
context.filter = window.getComputedStyle(img).filter;
|
|
context.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
context.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
return dataURLtoBlob(canvas.toDataURL());
|
|
return dataURLtoBlob(canvas.toDataURL());
|