``update Extract PocketBase URL to constant and refactor related functions to use it for dynamic file URL generation``

This commit is contained in:
2025-05-16 15:55:47 +08:00
parent c87357ff24
commit 60df47fb8d
3 changed files with 17 additions and 3 deletions

View File

@@ -0,0 +1,10 @@
//
// PURPOSE:
// get file url from pocketbase record
//
import { POCKETBASE_URL } from '../constants';
export default function getImageUrlFromFile(collectionId: string, id: string, imgFile: string | undefined): string {
return `${POCKETBASE_URL}/api/files/${collectionId}/${id}/${imgFile}`;
}

View File

@@ -1,5 +1,7 @@
import { POCKETBASE_URL } from '../constants';
import { DBUserMeta } from '../db/UserMetas/type';
export function getStudentAvatar(studentMeta: DBUserMeta) {
return `url(http://localhost:8090/api/files/${studentMeta.collectionId}/${studentMeta.id}/${studentMeta.avatar})`;
export function getStudentAvatarUrl(studentMeta: DBUserMeta) {
const { collectionId, id, avatar } = studentMeta;
return `url(${POCKETBASE_URL}/api/files/${collectionId}/${id}/${avatar})`;
}

View File

@@ -1,5 +1,7 @@
import PocketBase from 'pocketbase';
import { ERR_POCKETBASE_URL_IS_EMPTY } from '../ERRORS';
import { POCKETBASE_URL } from '../constants';
const pb = new PocketBase('http://127.0.0.1:8090');
const pb = new PocketBase(POCKETBASE_URL);
export { pb };