feat: add snippet and test for supa db
This commit is contained in:
@@ -140,44 +140,49 @@ app
|
||||
middleware: ['auth'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const { appKey, files, version } = ctx.query.data;
|
||||
if (!appKey) {
|
||||
throw new CustomError('appKey is required');
|
||||
}
|
||||
if (!files || !files.length) {
|
||||
throw new CustomError('files is required');
|
||||
}
|
||||
let am = await AppModel.findOne({ where: { key: appKey, uid: tokenUser.id } });
|
||||
if (!am) {
|
||||
am = await AppModel.create({
|
||||
user: tokenUser.username,
|
||||
key: appKey,
|
||||
uid: tokenUser.id,
|
||||
version: '0.0.0',
|
||||
title: appKey,
|
||||
data: {
|
||||
files: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
let app = await AppListModel.findOne({ where: { version: version, key: appKey, uid: tokenUser.id } });
|
||||
if (!app) {
|
||||
// throw new CustomError('app not found');
|
||||
app = await AppListModel.create({
|
||||
key: appKey,
|
||||
version,
|
||||
uid: tokenUser.id,
|
||||
data: {
|
||||
files: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
const dataFiles = app.data.files || [];
|
||||
const newFiles = _.uniqBy([...dataFiles, ...files], 'name');
|
||||
const res = await app.update({ data: { ...app.data, files: newFiles } });
|
||||
try {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const { appKey, files, version } = ctx.query.data;
|
||||
if (!appKey) {
|
||||
throw new CustomError('appKey is required');
|
||||
}
|
||||
if (!files || !files.length) {
|
||||
throw new CustomError('files is required');
|
||||
}
|
||||
let am = await AppModel.findOne({ where: { key: appKey, uid: tokenUser.id } });
|
||||
if (!am) {
|
||||
am = await AppModel.create({
|
||||
user: tokenUser.username,
|
||||
key: appKey,
|
||||
uid: tokenUser.id,
|
||||
version: '0.0.0',
|
||||
title: appKey,
|
||||
data: {
|
||||
files: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
let app = await AppListModel.findOne({ where: { version: version, key: appKey, uid: tokenUser.id } });
|
||||
if (!app) {
|
||||
// throw new CustomError('app not found');
|
||||
app = await AppListModel.create({
|
||||
key: appKey,
|
||||
version,
|
||||
uid: tokenUser.id,
|
||||
data: {
|
||||
files: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
const dataFiles = app.data.files || [];
|
||||
const newFiles = _.uniqBy([...dataFiles, ...files], 'name');
|
||||
const res = await app.update({ data: { ...app.data, files: newFiles } });
|
||||
|
||||
ctx.body = prefixFix(res, tokenUser.username);
|
||||
ctx.body = prefixFix(res, tokenUser.username);
|
||||
} catch (e) {
|
||||
console.log('update error', e);
|
||||
throw new CustomError(e.message);
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
|
||||
1
src/routes/snippet/index.ts
Normal file
1
src/routes/snippet/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
import './list.ts'
|
||||
13
src/routes/snippet/list.ts
Normal file
13
src/routes/snippet/list.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Snippet } from '@/models-supa/snippet.ts';
|
||||
import { app } from '@/app.ts';
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'snippet',
|
||||
key: 'list',
|
||||
middleware: ['auth'],
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
// 获取所有的snippet
|
||||
})
|
||||
.addTo(app);
|
||||
Reference in New Issue
Block a user