refactor: add base in url
This commit is contained in:
parent
f2b318060e
commit
62269efbb6
1 changed files with 16 additions and 10 deletions
|
|
@ -237,8 +237,10 @@ export function resetScrollBar(elementId: string) {
|
||||||
|
|
||||||
export function manageAttachment(api: AxiosInstance, base: string) {
|
export function manageAttachment(api: AxiosInstance, base: string) {
|
||||||
return {
|
return {
|
||||||
listAttachment: async () => {
|
listAttachment: async (opts: { parentId: string }) => {
|
||||||
const res = await api.get<string[]>(`${base}/attachment`);
|
const res = await api.get<string[]>(
|
||||||
|
`${base}/${opts.parentId}/attachment`,
|
||||||
|
);
|
||||||
if (res.status >= 400) return false;
|
if (res.status >= 400) return false;
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
|
|
@ -247,7 +249,7 @@ export function manageAttachment(api: AxiosInstance, base: string) {
|
||||||
name: string;
|
name: string;
|
||||||
download?: boolean;
|
download?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const url = `/${opts.parentId}/attachment/${opts.name}`;
|
const url = `${base}/${opts.parentId}/attachment/${opts.name}`;
|
||||||
const res = await api.get<string>(url);
|
const res = await api.get<string>(url);
|
||||||
if (opts.download) {
|
if (opts.download) {
|
||||||
fetch(res.data)
|
fetch(res.data)
|
||||||
|
|
@ -268,7 +270,7 @@ export function manageAttachment(api: AxiosInstance, base: string) {
|
||||||
file: File;
|
file: File;
|
||||||
}) => {
|
}) => {
|
||||||
const res = await api.put(
|
const res = await api.put(
|
||||||
`/${opts.parentId}/attachment/${opts.name}`,
|
`${base}/${opts.parentId}/attachment/${opts.name}`,
|
||||||
opts.file,
|
opts.file,
|
||||||
{
|
{
|
||||||
headers: { 'Content-Type': opts.file.type },
|
headers: { 'Content-Type': opts.file.type },
|
||||||
|
|
@ -279,7 +281,9 @@ export function manageAttachment(api: AxiosInstance, base: string) {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
delAttachment: async (opts: { parentId: string; name: string }) => {
|
delAttachment: async (opts: { parentId: string; name: string }) => {
|
||||||
const res = await api.delete(`/${opts.parentId}/attachment/${opts.name}`);
|
const res = await api.delete(
|
||||||
|
`${base}/${opts.parentId}/attachment/${opts.name}`,
|
||||||
|
);
|
||||||
if (res.status < 400) return true;
|
if (res.status < 400) return true;
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
@ -288,8 +292,10 @@ export function manageAttachment(api: AxiosInstance, base: string) {
|
||||||
|
|
||||||
export function manageFile<T extends string>(api: AxiosInstance, base: string) {
|
export function manageFile<T extends string>(api: AxiosInstance, base: string) {
|
||||||
return {
|
return {
|
||||||
listFile: async (opts: { group: T }) => {
|
listFile: async (opts: { group: T; parentId: string }) => {
|
||||||
const res = await api.get<string[]>(`${base}/file-${opts.group}`);
|
const res = await api.get<string[]>(
|
||||||
|
`${base}/${opts.parentId}/file-${opts.group}`,
|
||||||
|
);
|
||||||
if (res.status >= 400) return false;
|
if (res.status >= 400) return false;
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
|
|
@ -299,7 +305,7 @@ export function manageFile<T extends string>(api: AxiosInstance, base: string) {
|
||||||
fileId: string;
|
fileId: string;
|
||||||
download?: boolean;
|
download?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const url = `/${opts.parentId}/file-${opts.group}/${opts.fileId}`;
|
const url = `${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`;
|
||||||
const res = await api.get<string>(url);
|
const res = await api.get<string>(url);
|
||||||
if (opts.download) {
|
if (opts.download) {
|
||||||
fetch(res.data)
|
fetch(res.data)
|
||||||
|
|
@ -321,7 +327,7 @@ export function manageFile<T extends string>(api: AxiosInstance, base: string) {
|
||||||
file: File;
|
file: File;
|
||||||
}) => {
|
}) => {
|
||||||
const res = await api.put(
|
const res = await api.put(
|
||||||
`/${opts.parentId}/file-${opts.group}/${opts.fileId}`,
|
`${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`,
|
||||||
opts.file,
|
opts.file,
|
||||||
{
|
{
|
||||||
headers: { 'Content-Type': opts.file.type },
|
headers: { 'Content-Type': opts.file.type },
|
||||||
|
|
@ -333,7 +339,7 @@ export function manageFile<T extends string>(api: AxiosInstance, base: string) {
|
||||||
},
|
},
|
||||||
delFile: async (opts: { group: T; parentId: string; fileId: string }) => {
|
delFile: async (opts: { group: T; parentId: string; fileId: string }) => {
|
||||||
const res = await api.delete(
|
const res = await api.delete(
|
||||||
`/${opts.parentId}/file-${opts.group}/${opts.fileId}`,
|
`${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`,
|
||||||
);
|
);
|
||||||
if (res.status < 400) return true;
|
if (res.status < 400) return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue