Skip to main content
Glama
assets.ts1.55 kB
import { writeFile } from "node:fs/promises"; import { mkdir } from "node:fs/promises"; import { join } from "node:path"; import { createId } from "@paralleldrive/cuid2"; import { eq } from "drizzle-orm"; import { db } from "../../index"; import { assets } from "../../schema"; import { AssetType } from "../../types"; const UPLOAD_DIR = process.env.UPLOAD_DIR || "uploads"; export const saveAsset = async ({ userId, assetType = "unknown", contentType, fileName, size, buffer, bookmarkId = null, }: { userId: string; assetType?: AssetType; contentType: string; fileName: string; size: number; buffer: Buffer; bookmarkId?: string | null; }) => { // 创建上传目录 const uploadPath = join(UPLOAD_DIR, userId); await mkdir(uploadPath, { recursive: true }); // 生成唯一的文件名 const uniqueFileName = `${createId()}-${fileName}`; const filePath = join(uploadPath, uniqueFileName); // 保存文件 await writeFile(filePath, buffer); // 保存到数据库 const [asset] = await db .insert(assets) .values({ id: createId(), userId, assetType: assetType as AssetType, contentType, fileName, size, path: filePath, bookmarkId, }) .returning(); return asset; }; export const getAssetById = async (id: string) => { const asset = await db.query.assets.findFirst({ where: eq(assets.id, id), }); return asset; }; export const deleteAsset = async (id: string) => { await db.delete(assets).where(eq(assets.id, id)); };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/metacode0602/open-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server