feat: remove old data import scripts and JSON files
- Deleted `import-data.ts` and `import-life.ts` scripts for importing short-link and life JSON data into the database. - Removed `ncode-list.json` containing short-link data. - Added new script `mv-resources.ts` for migrating resources from username-based paths to userId-based paths in the database and object storage. - Introduced `UserId` module for fetching user IDs and usernames from the database with caching. - Updated `UserApp` class to use user IDs instead of usernames for resource paths. - Modified routes to include a new endpoint for retrieving user IDs based on usernames.
This commit is contained in:
@@ -4,6 +4,8 @@ import { CustomError } from '@kevisual/router';
|
||||
import { checkUsername } from './admin/user.ts';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { sql } from 'drizzle-orm';
|
||||
import z from 'zod';
|
||||
import { UserId } from './modules/user-id.ts';
|
||||
|
||||
app
|
||||
.route({
|
||||
@@ -91,3 +93,27 @@ app
|
||||
};
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
app.route({
|
||||
path: 'user',
|
||||
key: 'uid',
|
||||
description: '根据用户名获取用户ID',
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
args: {
|
||||
username: z.string().describe('username is required'),
|
||||
}
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const { username } = ctx.query || {};
|
||||
if (!username) {
|
||||
ctx.throw(400, { message: 'username is required' });
|
||||
}
|
||||
const userId = await UserId.getUserIdByName(username);
|
||||
if (!userId) {
|
||||
ctx.throw(404, { message: 'user not found' });
|
||||
}
|
||||
ctx.body = {
|
||||
id: userId,
|
||||
};
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user