Skip to content

Commit

Permalink
Pass the right parameters to the cloud apis
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Sep 28, 2023
1 parent 93451c6 commit f3ad3a5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cloud/server/CloudConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 5 additions & 1 deletion src/cloud/server/CloudHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class CloudApi implements Media, Target, History {
ctx: Connection.Context
): Promise<Connection.UploadResponse> {
return fetch(
cloudConfig.media,
cloudConfig.upload,
withAuth(
ctx,
asJson({
Expand All @@ -75,6 +75,10 @@ export class CloudApi implements Media, Target, History {
.then<OutcomeJSON<Connection.UploadResponse>>(json)
.then<Outcome<Connection.UploadResponse>>(Outcome.fromJSON)
.then(Outcome.unpack)
.then(info => {
if ('filename' in info) info.location = info.filename as string
return info
})
}

delete(
Expand Down
1 change: 0 additions & 1 deletion src/core/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export namespace Connection {
upload: {
url: string
method?: string
headers?: Record<string, string>
}
}
export interface ResolveParams extends ResolveDefaults {
Expand Down
1 change: 1 addition & 0 deletions src/core/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export interface MoveMutation {
export interface UploadMutation {
type: MutationType.Upload
entryId: string
fileId: string
file: string
}

Expand Down
11 changes: 6 additions & 5 deletions src/dashboard/hook/UseUploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -176,7 +175,8 @@ async function process(
{
type: MutationType.Upload,
entryId: entry.entryId,
file
fileId: upload.info!.fileId,
file: upload.info!.location
}
])

Expand All @@ -195,6 +195,7 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) {
const [uploads, setUploads] = useState<Array<Upload>>([])

async function createEntry(upload: Upload) {
const entryId = createId()
const {parentId} = upload.to
const buffer = await upload.file.arrayBuffer()
const contentHash = await createContentHash(
Expand Down Expand Up @@ -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 =
Expand All @@ -239,15 +240,15 @@ 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),
seeded: false,
modifiedAt: Date.now(),
searchableText: '',
index: generateKeyBetween(null, prev?.index ?? null),
i18nId: fileId,
i18nId: entryId,

level: parent ? parent.level + 1 : 0,
parentDir: parentDir,
Expand Down

0 comments on commit f3ad3a5

Please sign in to comment.