fix: delete and restore for dynamic urls for minio hosted images fix… (#3452)

* feat: delete and restore for dynamic urls for minio hosted images fixed in spaces

* feat: delete and restore images calls fixed for web
This commit is contained in:
M. Palanikannan 2024-01-24 18:56:19 +05:30 committed by GitHub
parent 6a2be6afc4
commit 8d3ea5bb3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 143 additions and 36 deletions

View file

@ -74,6 +74,39 @@ class FileService extends APIService {
};
}
getDeleteImageFunction(workspaceId: string) {
return async (src: string) => {
try {
const assetUrlWithWorkspaceId = `${workspaceId}/${this.extractAssetIdFromUrl(src, workspaceId)}`;
const data = await this.deleteImage(assetUrlWithWorkspaceId);
return data;
} catch (e) {
console.error(e);
}
};
}
getRestoreImageFunction(workspaceId: string) {
return async (src: string) => {
try {
const assetUrlWithWorkspaceId = `${workspaceId}/${this.extractAssetIdFromUrl(src, workspaceId)}`;
const data = await this.restoreImage(assetUrlWithWorkspaceId);
return data;
} catch (e) {
console.error(e);
}
};
}
extractAssetIdFromUrl(src: string, workspaceId: string): string {
const indexWhereAssetIdStarts = src.indexOf(workspaceId) + workspaceId.length + 1;
if (indexWhereAssetIdStarts === -1) {
throw new Error("Workspace ID not found in source string");
}
const assetUrl = src.substring(indexWhereAssetIdStarts);
return assetUrl;
}
async deleteImage(assetUrlWithWorkspaceId: string): Promise<any> {
return this.delete(`/api/workspaces/file-assets/${assetUrlWithWorkspaceId}/`)
.then((response) => response?.status)