mirror of
https://github.com/asphyxia-core/plugins.git
synced 2026-09-30 22:06:47 -05:00
[sdvx] v1.0
This commit is contained in:
@@ -69,11 +69,11 @@ export const saveMix: EPR = async (info, data, send) => {
|
||||
|
||||
const id = await GetCounter('mix');
|
||||
let code = _.padStart(_.random(0, 999999999999).toString(), 12, '0');
|
||||
while (await DB.FindOne<Mix>(null, { code })) {
|
||||
while (await DB.FindOne<Mix>({ collection: 'mix', code })) {
|
||||
code = _.padStart(_.random(0, 999999999999).toString(), 12, '0');
|
||||
}
|
||||
|
||||
const doc = await DB.Insert<Mix>(refid, {
|
||||
const doc = await DB.Insert<Mix>({
|
||||
collection: 'mix',
|
||||
id,
|
||||
code,
|
||||
@@ -103,7 +103,7 @@ export const saveMix: EPR = async (info, data, send) => {
|
||||
export const loadMix: EPR = async (info, data, send) => {
|
||||
const code = $(data).str('mix_code');
|
||||
|
||||
const mix = await DB.FindOne<Mix>(null, { collection: 'mix', code });
|
||||
const mix = await DB.FindOne<Mix>({ collection: 'mix', code });
|
||||
if (!mix) {
|
||||
send.object({ result: K.ITEM('s32', 1) });
|
||||
return;
|
||||
|
||||
@@ -18,7 +18,7 @@ async function getAutomationMixes(params: Param[]) {
|
||||
const mixids = params
|
||||
.filter(p => p.id == 3)
|
||||
.reduce((res, p) => _.union(res, p.param), []);
|
||||
return await DB.Find<Mix>(null, { collection: 'mix', id: { $in: mixids } });
|
||||
return await DB.Find<Mix>({ collection: 'mix', id: { $in: mixids } });
|
||||
}
|
||||
|
||||
function unlockNavigators(items: Partial<Item>[]) {
|
||||
|
||||
117
sdvx@asphyxia/handlers/webui.ts
Normal file
117
sdvx@asphyxia/handlers/webui.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import { Profile } from '../models/profile';
|
||||
import { Mix } from '../models/mix';
|
||||
import { GetCounter } from '../utils';
|
||||
|
||||
export const updateProfile = async (data: {
|
||||
refid: string;
|
||||
name?: string;
|
||||
appeal?: string;
|
||||
akaname?: string;
|
||||
}) => {
|
||||
if (data.refid == null) return;
|
||||
|
||||
const update: Update<Profile>['$set'] = {};
|
||||
|
||||
if (data.name && data.name.length > 0) {
|
||||
const validName = data.name
|
||||
.toUpperCase()
|
||||
.replace(/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?#$&*\-\.\ ]/g, '')
|
||||
.slice(0, 8);
|
||||
if (validName.length > 0) update.name = validName;
|
||||
}
|
||||
|
||||
if (data.appeal && data.appeal.length > 0) {
|
||||
const validAppeal = parseInt(data.appeal);
|
||||
if (!_.isNaN(validAppeal)) update.appeal = validAppeal;
|
||||
}
|
||||
|
||||
if (data.akaname && data.akaname.length > 0) {
|
||||
const validAka = parseInt(data.akaname);
|
||||
if (!_.isNaN(validAka)) update.akaname = validAka;
|
||||
}
|
||||
|
||||
await DB.Update<Profile>(
|
||||
data.refid,
|
||||
{ collection: 'profile' },
|
||||
{ $set: update }
|
||||
);
|
||||
};
|
||||
|
||||
export const updateMix = async (data: {
|
||||
code: string;
|
||||
name?: string;
|
||||
creator?: string;
|
||||
}) => {
|
||||
const update: Update<Mix>['$set'] = {};
|
||||
|
||||
if (data.name && data.name.length > 0) {
|
||||
if (data.name.length > 0) update.name = data.name;
|
||||
}
|
||||
|
||||
if (data.creator && data.creator.length > 0) {
|
||||
// const validCreator = data.creator
|
||||
// .toUpperCase()
|
||||
// .replace(/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?#$&*\-\.\ ]/g, '')
|
||||
// .slice(0, 8);
|
||||
if (data.creator.length > 0) update.creator = data.creator;
|
||||
}
|
||||
|
||||
await DB.Update<Mix>(
|
||||
{ collection: 'mix', code: data.code },
|
||||
{ $set: update }
|
||||
);
|
||||
};
|
||||
|
||||
export const importMix = async (data: { json: string }) => {
|
||||
if (data.json.startsWith('`')) {
|
||||
data.json = data.json.slice(1);
|
||||
}
|
||||
|
||||
if (data.json.endsWith('`')) {
|
||||
data.json = data.json.slice(0, data.json.length - 1);
|
||||
}
|
||||
|
||||
const mix: any[] = JSON.parse(data.json);
|
||||
|
||||
let code = mix[0];
|
||||
while (await DB.FindOne<Mix>({ collection: 'mix', code })) {
|
||||
code = _.padStart(_.random(0, 999999999999).toString(), 12, '0');
|
||||
}
|
||||
|
||||
const id = await GetCounter('mix');
|
||||
const musics = mix.slice(9);
|
||||
|
||||
if (musics.length % 2 !== 0) return;
|
||||
|
||||
const mdata = [];
|
||||
|
||||
for (let i = 0; i < musics.length; i += 2) {
|
||||
mdata.push({
|
||||
grade: musics[i + 1],
|
||||
id: musics[i],
|
||||
});
|
||||
}
|
||||
|
||||
await DB.Insert<Mix>({
|
||||
collection: 'mix',
|
||||
code,
|
||||
id,
|
||||
name: mix[1],
|
||||
creator: mix[2],
|
||||
param: `{ "dbVer" : "${
|
||||
mix[3]
|
||||
}", "gene" : { "params" : "{ \\"minorVer\\" : \\"${
|
||||
mix[4]
|
||||
}\\", \\"seed\\" : ${mix[5]} }", "ver" : "${
|
||||
mix[6]
|
||||
}" }, "musics" : ${JSON.stringify(mdata)}, "voxdj" : { "params" : "${
|
||||
mix[7]
|
||||
}", "ver" : "${mix[8]}" } }`,
|
||||
jacket: 0,
|
||||
tag: 1,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteMix = async (data: { code: string }) => {
|
||||
await DB.Remove<Mix>({ collection: 'mix', code: data.code });
|
||||
};
|
||||
Reference in New Issue
Block a user