Initial commit: ACE-Step UI - Open source music generation interface
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { pool } from '../db/pool.js';
|
||||
|
||||
async function run() {
|
||||
const users = await pool.query(
|
||||
`SELECT id, email FROM users
|
||||
WHERE avatar_url IS NULL AND email IS NOT NULL`
|
||||
);
|
||||
|
||||
let updated = 0;
|
||||
for (const row of users.rows) {
|
||||
const email = String(row.email || '').toLowerCase();
|
||||
if (!email) continue;
|
||||
const hash = await hashEmail(email);
|
||||
const gravatar = `https://www.gravatar.com/avatar/${hash}?d=identicon&s=256`;
|
||||
await pool.query(
|
||||
`UPDATE users SET avatar_url = $1 WHERE id = $2`,
|
||||
[gravatar, row.id]
|
||||
);
|
||||
updated += 1;
|
||||
}
|
||||
|
||||
console.log(`[backfill] Updated ${updated} users with gravatar identicons.`);
|
||||
await pool.end();
|
||||
}
|
||||
|
||||
async function hashEmail(email: string): Promise<string> {
|
||||
const crypto = await import('crypto');
|
||||
return crypto.createHash('md5').update(email.trim().toLowerCase()).digest('hex');
|
||||
}
|
||||
|
||||
run().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import { generationQueue } from '../services/generationQueue.js';
|
||||
|
||||
function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const results: string[] = [];
|
||||
|
||||
generationQueue.setConfig({
|
||||
maxTotalWorkers: 2,
|
||||
maxFreeWorkers: 1,
|
||||
maxPerUser: 1,
|
||||
batchWindowMs: 200,
|
||||
batchSize: 4,
|
||||
});
|
||||
|
||||
const jobs = [
|
||||
{ id: 'job-free-1', userId: 'u1', tier: 'free', delay: 300 },
|
||||
{ id: 'job-pro-1', userId: 'u2', tier: 'pro', delay: 200 },
|
||||
{ id: 'job-pro-2', userId: 'u2', tier: 'pro', delay: 200 },
|
||||
{ id: 'job-unlimited-1', userId: 'u3', tier: 'unlimited', delay: 150 },
|
||||
];
|
||||
|
||||
const done = new Promise<void>((resolve) => {
|
||||
let remaining = jobs.length;
|
||||
for (const job of jobs) {
|
||||
generationQueue.enqueue({
|
||||
id: job.id,
|
||||
userId: job.userId,
|
||||
tier: job.tier as 'free' | 'pro' | 'unlimited',
|
||||
createdAt: Date.now(),
|
||||
params: {
|
||||
lyrics: 'test',
|
||||
style: 'test',
|
||||
title: 'test',
|
||||
duration: 30,
|
||||
},
|
||||
run: async () => {
|
||||
results.push(`start:${job.id}`);
|
||||
await sleep(job.delay);
|
||||
results.push(`end:${job.id}`);
|
||||
generationQueue.markJobFinished(job.id);
|
||||
remaining -= 1;
|
||||
if (remaining === 0) {
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await done;
|
||||
|
||||
console.log('[test-queue] Order:', results.join(' | '));
|
||||
console.log('[test-queue] OK');
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error('[test-queue] Failed', error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user