Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spx-gui: delay input URL processing in RemoveBackground component #669

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
import { ref } from 'vue'
import { loadImg } from '@/utils/dom'
import { stripExt } from '@/utils/path'
import { untilNotNull, useAsyncComputed, memoizeAsync } from '@/utils/utils'
import { memoizeAsync } from '@/utils/utils'
import { getMimeFromExt } from '@/utils/file'
import { toJpeg } from '@/utils/img'
import { matting } from '@/apis/aigc'
import { fromBlob, toNativeFile, File } from '@/models/common/file'
import { createFileWithWebUrl, getWebUrl } from '@/models/common/cloud'
import { createFileWithWebUrl, saveFileForWebUrl } from '@/models/common/cloud'
import type { MethodComponentEmits, MethodComponentProps } from '../common/types'
import ProcessDetail from '../common/ProcessDetail.vue'
import ImgPreview from '../common/ImgPreview.vue'
const props = defineProps<MethodComponentProps>()
const emit = defineEmits<MethodComponentEmits>()
const inputUrlsComputed = useAsyncComputed(() =>
const getUrls = memoizeAsync((files: File[]) =>
Promise.all(
props.input.map(async (file) => {
files.map(async (file) => {
file = await adaptImg(file)
return getWebUrl(file)
return saveFileForWebUrl(file)
})
)
)
Expand All @@ -48,15 +48,15 @@ const batchRemoveBackground = memoizeAsync(
)
async function apply() {
const inputUrls = await untilNotNull(inputUrlsComputed)
const inputUrls = await getUrls(props.input)
const outputUrls = await batchRemoveBackground(inputUrls)
await drawTransitions(outputUrls)
const outputFiles = outputUrls.map((url) => createFileWithWebUrl(url))
emit('applied', outputFiles)
}
async function cancel() {
const inputUrls = await untilNotNull(inputUrlsComputed)
const inputUrls = await getUrls(props.input)
await drawTransitions(inputUrls, true)
emit('cancel')
}
Expand Down
2 changes: 1 addition & 1 deletion spx-gui/src/models/common/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function createFileWithWebUrl(url: WebUrl, name = filename(url)) {
})
}

export async function getWebUrl(file: File) {
export async function saveFileForWebUrl(file: File) {
const universalUrl = await saveFile(file)
return universalUrlToWebUrl(universalUrl)
}
Expand Down
Loading