temp
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { app } from './index.ts';
|
||||
import '@/modules/dev/add-auth.ts';
|
||||
|
||||
app.listen(4000, () => {
|
||||
console.log('Server is running on http://localhost:4000');
|
||||
|
||||
@@ -2,6 +2,10 @@ import { app, config, oss } from '../app.ts';
|
||||
import { dashscopeTTS } from '@/examples/dash-scope/tts.ts';
|
||||
import { randomLetter } from '@/utils/random.ts';
|
||||
import dayjs from 'dayjs';
|
||||
const isAdmin = (tokenUser: any) => {
|
||||
const username = tokenUser?.username || '';
|
||||
return username === 'admin' || username === 'root';
|
||||
};
|
||||
type DashScopeTTSResponse = {
|
||||
output?: {
|
||||
finish_reason?: string;
|
||||
@@ -30,12 +34,27 @@ app
|
||||
.route({
|
||||
path: 'aliyun-ai',
|
||||
key: 'createVideos',
|
||||
middleware: ['auth-can'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const { text, model, save = 'none' } = ctx.query;
|
||||
const tokenUser = ctx.state?.tokenUser;
|
||||
if (!text) {
|
||||
ctx.throw(400, 'Text and model are required parameters');
|
||||
ctx.throw(400, '文字text参数不能为空');
|
||||
}
|
||||
const admin = isAdmin(tokenUser);
|
||||
if (!tokenUser?.id) {
|
||||
if (text.length > 300) {
|
||||
// 大概1分钟
|
||||
ctx.throw(400, '文字长度超过限制,未登录用户最多只能输入300个字符');
|
||||
}
|
||||
} else if (!admin) {
|
||||
if (text.length > 1000) {
|
||||
// 大概3分钟
|
||||
ctx.throw(400, '文字长度超过限制,登录用户最多只能输入1000个字符');
|
||||
}
|
||||
}
|
||||
|
||||
const value: DashScopeTTSResponse = await dashscopeTTS({
|
||||
text,
|
||||
voice: model || 'Chelsie',
|
||||
@@ -43,7 +62,7 @@ app
|
||||
});
|
||||
const url = value?.output?.audio?.url;
|
||||
const fileName = `audio-${randomLetter(32)}.wav`;
|
||||
const username = 'share';
|
||||
const username = tokenUser?.username || 'share';
|
||||
const today = dayjs().format('YYYY-MM-DD');
|
||||
// 使用用户名和日期作为文件夹路径
|
||||
const filePath = `${username}/storage/aliyun-ai/audio/${today}/${fileName}`;
|
||||
|
||||
Reference in New Issue
Block a user