0.1.0 • Published 4 months ago
@sgrnext/api-upflow v0.1.0
@sgrnext/api-upflow
Getting started
Install
npm install --save @sgrnext/api @sgrnext/api-upflow
Crate handlers factory
// src/server/handle.ts
import { upload } from "@sgrnext/api-upflow";
export const handlers = new HandlerFactory()
.plugin(upload(new UploadMongoAdapter("connection string or connection object")));
Create routes
// src/app/api/me/avatar/route.ts
import { handlers } from '@/server/handlers';
export PUT = handlers.create(async (env) => {
const { id } = await env.upload(`user:${user}`)
return { id, url: '/api/user/avatar/${id}' };
});
// src/app/api/avatar/route.ts
import { handlers } from '@/server/handlers';
export PUT = handlers.create(async (env) => {
const { id } = await env.params;
const result = await env.uploadGet(id);
if (result == null) {
throw new ApiError(404, 'Avatar not found')
}
return result;
});
0.1.0
4 months ago