diff --git a/src/cloud/server/CloudConfig.ts b/src/cloud/server/CloudConfig.ts index c9ad70874..96f28a857 100644 --- a/src/cloud/server/CloudConfig.ts +++ b/src/cloud/server/CloudConfig.ts @@ -9,7 +9,7 @@ export const cloudConfig = { auth: `${baseUrl}/auth`, handshake: `${baseUrl}/api/v1/handshake`, mutate: `${baseUrl}/api/v1/mutate`, - draft: `${baseUrl}/api/v1/draft`, + upload: `${baseUrl}/api/v1/upload`, media: `${baseUrl}/api/v1/media`, logout: `${baseUrl}/api/v1/logout`, history: `${baseUrl}/api/v1/history` diff --git a/src/cloud/server/CloudHandler.ts b/src/cloud/server/CloudHandler.ts index 0ed53355e..a11553365 100644 --- a/src/cloud/server/CloudHandler.ts +++ b/src/cloud/server/CloudHandler.ts @@ -62,7 +62,7 @@ export class CloudApi implements Media, Target, History { ctx: Connection.Context ): Promise { return fetch( - cloudConfig.media, + cloudConfig.upload, withAuth( ctx, asJson({ @@ -75,6 +75,10 @@ export class CloudApi implements Media, Target, History { .then>(json) .then>(Outcome.fromJSON) .then(Outcome.unpack) + .then(info => { + if ('filename' in info) info.location = info.filename as string + return info + }) } delete( diff --git a/src/core/Connection.ts b/src/core/Connection.ts index 3d442f794..2e24d7b25 100644 --- a/src/core/Connection.ts +++ b/src/core/Connection.ts @@ -48,7 +48,6 @@ export namespace Connection { upload: { url: string method?: string - headers?: Record } } export interface ResolveParams extends ResolveDefaults { diff --git a/src/core/Mutation.ts b/src/core/Mutation.ts index cc66054f1..2435a608f 100644 --- a/src/core/Mutation.ts +++ b/src/core/Mutation.ts @@ -97,6 +97,7 @@ export interface MoveMutation { export interface UploadMutation { type: MutationType.Upload entryId: string + fileId: string file: string } diff --git a/src/dashboard/hook/UseUploads.ts b/src/dashboard/hook/UseUploads.ts index 5d9a4b975..17574cb5b 100644 --- a/src/dashboard/hook/UseUploads.ts +++ b/src/dashboard/hook/UseUploads.ts @@ -152,7 +152,6 @@ async function process( const info = await client.prepareUpload(file) await fetch(info.upload.url, { method: info.upload.method ?? 'POST', - headers: info.upload.headers ?? {}, body: upload.file }).then(async result => { if (!result.ok) @@ -176,7 +175,8 @@ async function process( { type: MutationType.Upload, entryId: entry.entryId, - file + fileId: upload.info!.fileId, + file: upload.info!.location } ]) @@ -195,6 +195,7 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) { const [uploads, setUploads] = useState>([]) async function createEntry(upload: Upload) { + const entryId = createId() const {parentId} = upload.to const buffer = await upload.file.arrayBuffer() const contentHash = await createContentHash( @@ -228,7 +229,7 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) { ) const extension = extname(path) const parentDir = dirname(filePath) - const {fileId, location} = upload.info! + const {location} = upload.info! const workspace = Workspace.data(config.workspaces[upload.to.workspace]) const prefix = workspace.mediaDir && normalize(workspace.mediaDir) const fileLocation = @@ -239,7 +240,7 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) { const entry: Media.File = { ...entryLocation, parent: parent?.entryId ?? null, - entryId: fileId, + entryId: entryId, type: 'MediaFile', url: (parent ? parent.url : '/') + path, title: basename(path, extension), @@ -247,7 +248,7 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) { modifiedAt: Date.now(), searchableText: '', index: generateKeyBetween(null, prev?.index ?? null), - i18nId: fileId, + i18nId: entryId, level: parent ? parent.level + 1 : 0, parentDir: parentDir,