mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
fix how spz files are manually uploaded in tauri
This commit is contained in:
1 parent
75ab5887f7
commit
df2671b487
2 files changed
+79
-2
No files matched your search
@@ -7,7 +7,7 @@ import {
|
||||
import { ApiManager, ApiResponse } from "./ApiManager";
|
||||
import { authentication } from "~/signals";
|
||||
import type { Property } from "csstype";
|
||||
type Visibility = Property.Visibility;
|
||||
import { Visibility } from "~/enums";
|
||||
|
||||
import {
|
||||
FilterEngineCategories,
|
||||
@@ -333,4 +333,67 @@ export class MediaFilesApi extends ApiManager {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public async UploadSpzFile({
|
||||
file,
|
||||
fileName,
|
||||
uuid,
|
||||
maybe_title,
|
||||
maybe_visibility = Visibility.Public,
|
||||
}: {
|
||||
file: File;
|
||||
fileName: string;
|
||||
uuid: string;
|
||||
maybe_title?: string;
|
||||
maybe_visibility?: Visibility;
|
||||
}): Promise<ApiResponse<string>> {
|
||||
const endpoint = `${this.getApiSchemeAndHost()}/v1/media_files/upload/spz`;
|
||||
const options: Record<string, string | number | undefined> = {
|
||||
maybe_title,
|
||||
maybe_visibility: maybe_visibility?.toString(),
|
||||
};
|
||||
return this.Upload({ endpoint, blob: file, fileName, uuid, options });
|
||||
}
|
||||
|
||||
private async Upload({
|
||||
endpoint,
|
||||
uuid,
|
||||
blob,
|
||||
fileName,
|
||||
options,
|
||||
}: {
|
||||
endpoint: string;
|
||||
blob: Blob | File;
|
||||
fileName: string;
|
||||
uuid: string;
|
||||
options: Record<string, string | number | undefined>;
|
||||
}): Promise<ApiResponse<string>> {
|
||||
const formRecord = Object.entries(options).reduce(
|
||||
(allOptions, [key, value]) => {
|
||||
if (value === undefined) {
|
||||
return allOptions;
|
||||
}
|
||||
return { ...allOptions, [key]: value.toString() };
|
||||
},
|
||||
{} as Record<string, string>,
|
||||
);
|
||||
|
||||
return await this.postForm<{
|
||||
success: boolean;
|
||||
media_file_token?: string;
|
||||
BadInput?: string;
|
||||
}>({ endpoint, formRecord, blob, blobFileName: fileName, uuid })
|
||||
.then((response) => ({
|
||||
success: Boolean(response.success ?? false),
|
||||
data: response.media_file_token,
|
||||
errorMessage: response.BadInput,
|
||||
}))
|
||||
.catch((err) => {
|
||||
return {
|
||||
success: false,
|
||||
errorMessage: err.message,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+15
-1
@@ -1,4 +1,4 @@
|
||||
import { MediaUploadApi } from "~/Classes/ApiManager";
|
||||
import { MediaFilesApi, MediaUploadApi } from "~/Classes/ApiManager";
|
||||
import { FilterEngineCategories, MediaFileAnimationType } from "~/enums";
|
||||
import { getFileExtension } from "~/utilities";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
@@ -14,11 +14,24 @@ export const uploadAsset = async ({
|
||||
engineCategory: FilterEngineCategories;
|
||||
animationType?: MediaFileAnimationType;
|
||||
}) => {
|
||||
// TODO: 'media_uploads' is the name of an ancient table nothing writes to. We shouldn't use this name here to mean the media_files table.
|
||||
const mediaUploadApi = new MediaUploadApi();
|
||||
const mediaFileApi = new MediaFilesApi();
|
||||
|
||||
const fileExtension = getFileExtension(file);
|
||||
|
||||
const assetReponse = await (async () => {
|
||||
switch (fileExtension) {
|
||||
case ".spz":
|
||||
console.log("Uploading asset as SPZ");
|
||||
return mediaFileApi.UploadSpzFile({
|
||||
file: file,
|
||||
fileName: file.name,
|
||||
uuid: uuidv4(),
|
||||
maybe_title: title,
|
||||
});
|
||||
case ".zip":
|
||||
console.log("Uploading asset as PMX");
|
||||
return mediaUploadApi.UploadPmx({
|
||||
file: file,
|
||||
fileName: file.name,
|
||||
@@ -28,6 +41,7 @@ export const uploadAsset = async ({
|
||||
uuid: uuidv4(),
|
||||
});
|
||||
default:
|
||||
console.log("Uploading asset as generic engine asset");
|
||||
return mediaUploadApi.UploadNewEngineAsset({
|
||||
file: file,
|
||||
fileName: file.name,
|
||||
|
||||
Reference in new issue
Block a user