emojigen wip11

This commit is contained in:
こけっち 2022-05-05 16:31:44 +09:00
parent 5e3554d693
commit d59a072de7
No known key found for this signature in database
GPG Key ID: 21460619C5FC4DD1

View File

@ -70,6 +70,7 @@ import FormButton from '@/components/ui/button.vue';
import * as os from '@/os';
import * as symbols from '@/symbols';
import {defaultStore} from "@/store";
import {stream} from "@/stream";
export default defineComponent({
components: {
@ -118,20 +119,38 @@ export default defineComponent({
},
emojiApproval() {
const chooseFileFromPc = async () => {
const emojiUpload = async () => {
const marker = Math.random().toString(); // TODO: UUID使
const response = await fetch(this.emojiUrl).then(res => res.blob())
const connection = stream.useChannel('main');
connection.on('urlUploadFinished', data => {
if (data.marker === marker) {
emojiAdd(data.file.id);
connection.dispose();
}
});
await os.api('drive/files/upload-from-url', {
url: this.emojiUrl,
folderId: defaultStore.state.uploadFolder,
marker
});
const emojiAdd = async (fileId) => {
await os.api('drive/files/update', {
fileId,
name: this.emojiName + '.png',
});
await os.api('admin/emoji/add', {
fileId,
})
}
const file = new File([response], `${this.emojiName}.png`);
return await os.upload(file, defaultStore.state.uploadFolder, undefined,);
};
(async () => {
const fileId = await chooseFileFromPc().then(res => res.id);
await os.api('admin/emoji/add', {
fileId,
name: this.emojiName,
})
await emojiUpload();
})();
},
},