refactor: more TS code
This commit is contained in:
+18
-5
@@ -6,7 +6,7 @@ import IconUnknown from "../assets/icons/file.unknown.svg";
|
||||
import IconDoc from "../assets/icons/file.doc.svg";
|
||||
import IconCode from "../assets/icons/file.code.svg";
|
||||
import IconImage from "../assets/icons/file.image.svg";
|
||||
import { Archive } from "../types/resource";
|
||||
import { Archive, ArchiveMessage } from "../types/resource";
|
||||
|
||||
export const isImage = (file_type = "", size = 0) => {
|
||||
return file_type.startsWith("image") && size <= FILE_IMAGE_SIZE;
|
||||
@@ -40,7 +40,7 @@ export function getDefaultSize(size = null, min = 480) {
|
||||
return { width: dWidth, height: dHeight };
|
||||
}
|
||||
|
||||
export function formatBytes(bytes, decimals = 2) {
|
||||
export function formatBytes(bytes: number, decimals = 2) {
|
||||
if (bytes === 0) return "0 Bytes";
|
||||
|
||||
const k = 1000;
|
||||
@@ -51,7 +51,7 @@ export function formatBytes(bytes, decimals = 2) {
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
|
||||
}
|
||||
export const getImageSize = (url) => {
|
||||
export const getImageSize = (url: string) => {
|
||||
const size = { width: 0, height: 0 };
|
||||
if (!url) return size;
|
||||
return new Promise((resolve) => {
|
||||
@@ -67,7 +67,7 @@ export const getImageSize = (url) => {
|
||||
};
|
||||
});
|
||||
};
|
||||
export const getInitials = (name) => {
|
||||
export const getInitials = (name: string) => {
|
||||
const arr = name.split(" ").filter((n) => !!n);
|
||||
return arr
|
||||
.map((t) => t[0])
|
||||
@@ -178,7 +178,20 @@ export const normalizeArchiveData = (
|
||||
) => {
|
||||
if (!data || !filePath) return [];
|
||||
const { messages, users } = data;
|
||||
const getUrls = (uid, { content, content_type, file_id, thumbnail_id, filePath, avatar }) => {
|
||||
const getUrls = (
|
||||
uid: number | undefined,
|
||||
{
|
||||
content,
|
||||
content_type,
|
||||
file_id,
|
||||
thumbnail_id,
|
||||
filePath,
|
||||
avatar
|
||||
}: Partial<ArchiveMessage> & {
|
||||
filePath: string;
|
||||
avatar?: number | string;
|
||||
}
|
||||
) => {
|
||||
// uid存在,则favorite,否则archive
|
||||
const prefix = uid
|
||||
? `${BASE_URL}/favorite/attachment/${uid}/${filePath}/`
|
||||
|
||||
Reference in New Issue
Block a user