update nextcloud for file support
This commit is contained in:
@@ -68,4 +68,32 @@ export const nextcloudApi = {
|
||||
.post(`/api/nextcloud/talk/rooms/${encodeURIComponent(token)}/read`)
|
||||
.then(() => undefined);
|
||||
},
|
||||
|
||||
uploadFile(
|
||||
token: string,
|
||||
file: File,
|
||||
onProgress?: (pct: number) => void,
|
||||
): Promise<void> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return api
|
||||
.post(`/api/nextcloud/talk/rooms/${encodeURIComponent(token)}/files`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
onUploadProgress: onProgress
|
||||
? (e) => {
|
||||
if (e.total) onProgress(Math.round((e.loaded / e.total) * 100));
|
||||
}
|
||||
: undefined,
|
||||
})
|
||||
.then(() => undefined);
|
||||
},
|
||||
|
||||
getFileDownloadUrl(fileId: number | string, filePath?: string): string {
|
||||
const base = `/api/nextcloud/talk/files/${fileId}/download`;
|
||||
return filePath ? `${base}?path=${encodeURIComponent(filePath)}` : base;
|
||||
},
|
||||
|
||||
getFilePreviewUrl(fileId: number | string, w = 400, h = 400): string {
|
||||
return `/api/nextcloud/talk/files/${fileId}/preview?w=${w}&h=${h}`;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user