mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign). Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files) and align docker/Dockerfile turbo --scope/--filter to the actual remix package name @hanzo/esign (was a pre-existing mismatch with -remix that broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
57 lines
1.2 KiB
TypeScript
57 lines
1.2 KiB
TypeScript
import { match } from 'ts-pattern';
|
|
|
|
import { getSession } from '@hanzo/esign-auth/server/lib/utils/get-session';
|
|
|
|
import { ERROR_CODES } from './errors';
|
|
import { getServerLimits } from './server';
|
|
|
|
export const limitsHandler = async (req: Request) => {
|
|
try {
|
|
const { user } = await getSession(req);
|
|
|
|
const rawTeamId = req.headers.get('team-id');
|
|
|
|
let teamId: number | null = null;
|
|
|
|
if (typeof rawTeamId === 'string' && !isNaN(parseInt(rawTeamId, 10))) {
|
|
teamId = parseInt(rawTeamId, 10);
|
|
}
|
|
|
|
if (!teamId) {
|
|
throw new Error(ERROR_CODES.INVALID_TEAM_ID);
|
|
}
|
|
|
|
const limits = await getServerLimits({ userId: user.id, teamId });
|
|
|
|
return Response.json(limits, {
|
|
status: 200,
|
|
});
|
|
} catch (err) {
|
|
console.error('error', err);
|
|
|
|
if (err instanceof Error) {
|
|
const status = match(err.message)
|
|
.with(ERROR_CODES.UNAUTHORIZED, () => 401)
|
|
.otherwise(() => 500);
|
|
|
|
return Response.json(
|
|
{
|
|
error: ERROR_CODES[err.message] ?? ERROR_CODES.UNKNOWN,
|
|
},
|
|
{
|
|
status,
|
|
},
|
|
);
|
|
}
|
|
|
|
return Response.json(
|
|
{
|
|
error: ERROR_CODES.UNKNOWN,
|
|
},
|
|
{
|
|
status: 500,
|
|
},
|
|
);
|
|
}
|
|
};
|