mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
packages
This commit is contained in:
43
packages/strapi/src/helpers/auth.ts
Normal file
43
packages/strapi/src/helpers/auth.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import axios from "axios";
|
||||
|
||||
interface ILoginResponse {
|
||||
jwt: string;
|
||||
user: IUser;
|
||||
}
|
||||
|
||||
interface IRole {
|
||||
id: number | string;
|
||||
name: string;
|
||||
description: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface IUser {
|
||||
id: number | string;
|
||||
username: string;
|
||||
email: string;
|
||||
provider: string;
|
||||
confirmed: boolean;
|
||||
blocked: boolean;
|
||||
role: IRole;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export const AuthHelper = (apiUrl: string) => ({
|
||||
login: async (identifier: string, password: string) => {
|
||||
const url = `${apiUrl}/auth/local`;
|
||||
|
||||
return await axios.post<ILoginResponse>(url, {
|
||||
identifier,
|
||||
password,
|
||||
});
|
||||
},
|
||||
me: async (token: string) => {
|
||||
return await axios.get<IUser>(`${apiUrl}/users/me`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
2
packages/strapi/src/helpers/index.ts
Normal file
2
packages/strapi/src/helpers/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./auth";
|
||||
export * from "./normalize";
|
||||
50
packages/strapi/src/helpers/normalize.ts
Normal file
50
packages/strapi/src/helpers/normalize.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export const getValueProps = (data: any, imageUrl: string) => {
|
||||
if (!data) {
|
||||
return { fileList: [] };
|
||||
}
|
||||
|
||||
return {
|
||||
file: data.file,
|
||||
fileList:
|
||||
data.fileList ??
|
||||
(Array.isArray(data) ? data : [...data]).map((item: any) => {
|
||||
const file: any = {
|
||||
name: item.name,
|
||||
percent: item.percent,
|
||||
size: item.size,
|
||||
status: item.status,
|
||||
type: item.mime || item.type,
|
||||
uid: item.id,
|
||||
};
|
||||
|
||||
if (item.url) {
|
||||
file.url = `${imageUrl}${item.url}`;
|
||||
}
|
||||
|
||||
return file;
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
export const mediaUploadMapper = (params: any) => {
|
||||
Object.keys(params).map((item) => {
|
||||
if (params[item]) {
|
||||
const param = params[item].fileList;
|
||||
const isMediaField = Array.isArray(param);
|
||||
if (isMediaField) {
|
||||
const ids = [];
|
||||
for (const item of param) {
|
||||
if (item.response) {
|
||||
for (const response of item.response) {
|
||||
ids.push(response.id);
|
||||
}
|
||||
} else {
|
||||
ids.push(item.uid);
|
||||
}
|
||||
}
|
||||
params[item] = ids;
|
||||
}
|
||||
}
|
||||
});
|
||||
return params;
|
||||
};
|
||||
Reference in New Issue
Block a user