wip
This commit is contained in:
parent
214c8e86fa
commit
86f08300e1
|
@ -105,7 +105,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { inject, watch, nextTick, onMounted, defineAsyncComponent, provide, shallowRef, ref, computed, useTemplateRef } from 'vue';
|
import { inject, watch, nextTick, onMounted, defineAsyncComponent, provide, shallowRef, ref, computed, useTemplateRef, onUnmounted } from 'vue';
|
||||||
import * as mfm from 'mfm-js';
|
import * as mfm from 'mfm-js';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import insertTextAtCursor from 'insert-text-at-cursor';
|
import insertTextAtCursor from 'insert-text-at-cursor';
|
||||||
|
@ -218,6 +218,10 @@ const uploader = useUploader({
|
||||||
multiple: true,
|
multiple: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
uploader.abortAll();
|
||||||
|
});
|
||||||
|
|
||||||
uploader.events.on('itemUploaded', ctx => {
|
uploader.events.on('itemUploaded', ctx => {
|
||||||
files.value.push(ctx.item.uploaded!);
|
files.value.push(ctx.item.uploaded!);
|
||||||
uploader.removeItem(ctx.item);
|
uploader.removeItem(ctx.item);
|
||||||
|
|
|
@ -87,6 +87,7 @@ export type UploaderItem = {
|
||||||
isSensitive?: boolean;
|
isSensitive?: boolean;
|
||||||
caption?: string | null;
|
caption?: string | null;
|
||||||
abort?: (() => void) | null;
|
abort?: (() => void) | null;
|
||||||
|
abortPreprocess?: (() => void) | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getCompressionSettings(level: 0 | 1 | 2 | 3) {
|
function getCompressionSettings(level: 0 | 1 | 2 | 3) {
|
||||||
|
@ -403,6 +404,19 @@ export function useUploader(options: {
|
||||||
removeItem(item);
|
removeItem(item);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} else if (item.preprocessing && item.abortPreprocess != null) {
|
||||||
|
menu.push({
|
||||||
|
type: 'divider',
|
||||||
|
}, {
|
||||||
|
icon: 'ti ti-player-stop',
|
||||||
|
text: i18n.ts.abort,
|
||||||
|
danger: true,
|
||||||
|
action: () => {
|
||||||
|
if (item.abortPreprocess != null) {
|
||||||
|
item.abortPreprocess();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
} else if (item.uploading) {
|
} else if (item.uploading) {
|
||||||
menu.push({
|
menu.push({
|
||||||
type: 'divider',
|
type: 'divider',
|
||||||
|
@ -486,6 +500,10 @@ export function useUploader(options: {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item.abortPreprocess != null) {
|
||||||
|
item.abortPreprocess();
|
||||||
|
}
|
||||||
|
|
||||||
if (item.abort != null) {
|
if (item.abort != null) {
|
||||||
item.abort();
|
item.abort();
|
||||||
}
|
}
|
||||||
|
@ -496,6 +514,7 @@ export function useUploader(options: {
|
||||||
|
|
||||||
async function preprocess(item: UploaderItem): Promise<void> {
|
async function preprocess(item: UploaderItem): Promise<void> {
|
||||||
item.preprocessing = true;
|
item.preprocessing = true;
|
||||||
|
item.preprocessProgress = null;
|
||||||
|
|
||||||
if (IMAGE_PREPROCESS_NEEDED_TYPES.includes(item.file.type)) {
|
if (IMAGE_PREPROCESS_NEEDED_TYPES.includes(item.file.type)) {
|
||||||
try {
|
try {
|
||||||
|
@ -518,6 +537,7 @@ export function useUploader(options: {
|
||||||
}
|
}
|
||||||
|
|
||||||
item.preprocessing = false;
|
item.preprocessing = false;
|
||||||
|
item.preprocessProgress = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function preprocessForImage(item: UploaderItem): Promise<void> {
|
async function preprocessForImage(item: UploaderItem): Promise<void> {
|
||||||
|
@ -620,8 +640,17 @@ export function useUploader(options: {
|
||||||
|
|
||||||
currentConversion.onProgress = newProgress => item.preprocessProgress = newProgress;
|
currentConversion.onProgress = newProgress => item.preprocessProgress = newProgress;
|
||||||
|
|
||||||
|
item.abortPreprocess = () => {
|
||||||
|
item.abortPreprocess = null;
|
||||||
|
currentConversion.cancel();
|
||||||
|
item.preprocessing = false;
|
||||||
|
item.preprocessProgress = null;
|
||||||
|
};
|
||||||
|
|
||||||
await currentConversion.execute();
|
await currentConversion.execute();
|
||||||
|
|
||||||
|
item.abortPreprocess = null;
|
||||||
|
|
||||||
preprocessedFile = new Blob([output.target.buffer!], { type: output.format.mimeType });
|
preprocessedFile = new Blob([output.target.buffer!], { type: output.format.mimeType });
|
||||||
item.compressedSize = output.target.buffer!.byteLength;
|
item.compressedSize = output.target.buffer!.byteLength;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue