- added settings page and function

- add Role Ring for avatar and display role for user nav
This commit is contained in:
2026-01-06 21:37:53 +07:00
parent 8146565d2c
commit a4e96fe045
64 changed files with 2828 additions and 726 deletions

View File

@@ -1,25 +1,26 @@
import fs, { writeFile } from 'fs/promises'
import path from 'path'
import fs, { writeFile } from 'fs/promises';
import path from 'path';
const uploadDir = './data/avatar';
export async function saveFile(key: string, file: Buffer | File) {
const uploadDir = './files'
if (!uploadDir) {
throw new Error('Upload directory not found')
throw new Error('Upload directory not found');
}
const fileBuffer =
file instanceof File ? Buffer.from(await file.arrayBuffer()) : file
file instanceof File ? Buffer.from(await file.arrayBuffer()) : file;
const filePath = path.join(uploadDir, key)
const filePath = path.join(uploadDir, key);
try {
await fs.mkdir(uploadDir, { recursive: true })
await writeFile(filePath, fileBuffer)
return key
await fs.mkdir(uploadDir, { recursive: true });
await writeFile(filePath, fileBuffer);
return key;
} catch (error) {
console.error(`Error saving file: ${key}`, error)
console.error(`Error saving file: ${key}`, error);
throw new Error(
`Failed to save file: ${error instanceof Error ? error.message : 'Unknown error'}`,
)
);
}
}