mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
e01ca97fc9
* image restoration fixed (marks an image to be deleted after a week) * removed clgs * added image constraints * formatted editor-core package using yarn format * lite-text-editor nothing to format * rich-text-editor nothing to format * formatted document-editor with prettier * modified file service to follow api change * fixed more formatting in document editor * fixed all instances of types with that from the package * fixed delete to work consistently (minor optimizations turned off) * stop duplicate images inside editor * restore image on editor creation say if user A deletes image number 2, user B was also in the same issue and in their screen the image was there, if user B makes certain changes and that gets saved in backend, according to user B image 2 should exist but since user A deleted it, it'll not get restored and get deleted in 7 days, hence I've added a check such that whenever a issue loads we restore all images by default * added restore image function with types * replaced all instances to have restore image logic * fixed issue detail for peek view * disabled option to insert table inside a table
129 lines
3.5 KiB
TypeScript
129 lines
3.5 KiB
TypeScript
// services
|
|
import APIService from "services/api.service";
|
|
// helpers
|
|
import { API_BASE_URL } from "helpers/common.helper";
|
|
import axios from "axios";
|
|
|
|
interface UnSplashImage {
|
|
id: string;
|
|
created_at: Date;
|
|
updated_at: Date;
|
|
promoted_at: Date;
|
|
width: number;
|
|
height: number;
|
|
color: string;
|
|
blur_hash: string;
|
|
description: null;
|
|
alt_description: string;
|
|
urls: UnSplashImageUrls;
|
|
[key: string]: any;
|
|
}
|
|
|
|
interface UnSplashImageUrls {
|
|
raw: string;
|
|
full: string;
|
|
regular: string;
|
|
small: string;
|
|
thumb: string;
|
|
small_s3: string;
|
|
}
|
|
|
|
class FileService extends APIService {
|
|
private cancelSource: any;
|
|
|
|
constructor() {
|
|
super(API_BASE_URL);
|
|
this.uploadFile = this.uploadFile.bind(this);
|
|
this.deleteImage = this.deleteImage.bind(this);
|
|
this.restoreImage = this.restoreImage.bind(this);
|
|
this.cancelUpload = this.cancelUpload.bind(this);
|
|
}
|
|
|
|
async uploadFile(workspaceSlug: string, file: FormData): Promise<any> {
|
|
this.cancelSource = axios.CancelToken.source();
|
|
return this.post(`/api/workspaces/${workspaceSlug}/file-assets/`, file, {
|
|
headers: {
|
|
...this.getHeaders(),
|
|
"Content-Type": "multipart/form-data",
|
|
},
|
|
cancelToken: this.cancelSource.token,
|
|
})
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
if (axios.isCancel(error)) {
|
|
console.log(error.message);
|
|
} else {
|
|
console.log(error);
|
|
throw error?.response?.data;
|
|
}
|
|
});
|
|
}
|
|
|
|
cancelUpload() {
|
|
this.cancelSource.cancel("Upload cancelled");
|
|
}
|
|
|
|
getUploadFileFunction(workspaceSlug: string): (file: File) => Promise<string> {
|
|
return async (file: File) => {
|
|
const formData = new FormData();
|
|
formData.append("asset", file);
|
|
formData.append("attributes", JSON.stringify({}));
|
|
|
|
const data = await this.uploadFile(workspaceSlug, formData);
|
|
return data.asset;
|
|
};
|
|
}
|
|
|
|
async deleteImage(assetUrlWithWorkspaceId: string): Promise<any> {
|
|
return this.delete(`/api/workspaces/file-assets/${assetUrlWithWorkspaceId}/`)
|
|
.then((response) => response?.status)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async restoreImage(assetUrlWithWorkspaceId: string): Promise<any> {
|
|
return this.post(`/api/workspaces/file-assets/${assetUrlWithWorkspaceId}/restore/`, {
|
|
headers: this.getHeaders(),
|
|
"Content-Type": "application/json",
|
|
})
|
|
.then((response) => response?.status)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async deleteFile(workspaceId: string, assetUrl: string): Promise<any> {
|
|
const lastIndex = assetUrl.lastIndexOf("/");
|
|
const assetId = assetUrl.substring(lastIndex + 1);
|
|
|
|
return this.delete(`/api/workspaces/file-assets/${workspaceId}/${assetId}/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
async uploadUserFile(file: FormData): Promise<any> {
|
|
return this.mediaUpload(`/api/users/file-assets/`, file)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async deleteUserFile(assetUrl: string): Promise<any> {
|
|
const lastIndex = assetUrl.lastIndexOf("/");
|
|
const assetId = assetUrl.substring(lastIndex + 1);
|
|
|
|
return this.delete(`/api/users/file-assets/${assetId}`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
}
|
|
|
|
const fileService = new FileService();
|
|
|
|
export default fileService;
|