Skip to content

Commit e40b8b7

Browse files
committed
feat: add local QA initialization for clips, playlists, queues, and their resources
1 parent cc59674 commit e40b8b7

File tree

5 files changed

+214
-0
lines changed

5 files changed

+214
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
local_qa_init_data:
22
npm run faker local create/feeds-channels-items
33
npm run faker local create/accounts/accounts
4+
npm run faker local create/clips/clips
45
npm run faker local create/playlists/playlists
6+
npm run faker local create/playlists/playlistResources
7+
npm run faker local create/queues/queues
8+
npm run faker local create/queues/queueResources
59
npm run faker local create/stats/statsAggregated
610
npm run faker local create/accounts/accountFollowings

src/faker/create/clips/clips.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { AccountService, ClipService, ItemService } from 'podverse-orm';
2+
import { MediumEnum, SharableStatusEnum } from 'podverse-helpers';
3+
import { FAKER } from '../../constants';
4+
5+
export default async function () {
6+
const accountService = new AccountService();
7+
const clipService = new ClipService();
8+
const itemService = new ItemService();
9+
10+
const sharableStatuses = [
11+
SharableStatusEnum.Public,
12+
SharableStatusEnum.Unlisted,
13+
SharableStatusEnum.Private
14+
];
15+
16+
for (const acc of FAKER.ACCOUNTS) {
17+
try {
18+
const createdAccount = await accountService.getByEmail(acc.email);
19+
if (!createdAccount) throw new Error('Account not found after creation');
20+
21+
for (let i = 0; i < 30; i++) {
22+
const medium_id = i % 2 === 0 ? MediumEnum.Podcast : MediumEnum.Video;
23+
const item = await itemService.getRandomItem(medium_id);
24+
25+
26+
const maxTime = 600;
27+
const minDuration = 15;
28+
const setEndTime = Math.random() < 0.75;
29+
const start_time = Math.floor(Math.random() * (maxTime - minDuration));
30+
let end_time: number | undefined = undefined;
31+
if (setEndTime) {
32+
const maxEnd = Math.min(start_time + minDuration + Math.floor(Math.random() * (maxTime - start_time - minDuration)), maxTime);
33+
end_time = Math.max(start_time + minDuration, maxEnd);
34+
}
35+
36+
await clipService.create(createdAccount.id, {
37+
title: `Clip ${i + 1} for ${acc.email} with status ${sharableStatuses[i % sharableStatuses.length]}`,
38+
description: `Auto-generated clip #${i + 1} for ${acc.email} with status ${sharableStatuses[i % sharableStatuses.length]}`,
39+
item_id_text: item.id_text,
40+
sharable_status_id: sharableStatuses[i % sharableStatuses.length],
41+
start_time: start_time.toString(),
42+
...(end_time !== undefined ? { end_time: end_time.toString() } : {})
43+
});
44+
}
45+
} catch (err) {
46+
console.error(`Error creating account ${acc.email}:`, err);
47+
}
48+
}
49+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { AccountService, ClipService, ItemService, ItemSoundbiteService,
2+
PlaylistResourceService, PlaylistService } from 'podverse-orm';
3+
import { FAKER } from '../../constants';
4+
5+
export default async function () {
6+
const accountService = new AccountService();
7+
const clipService = new ClipService();
8+
const itemService = new ItemService();
9+
const itemSoundbiteService = new ItemSoundbiteService();
10+
const playlistService = new PlaylistService();
11+
const playlistResourceService = new PlaylistResourceService();
12+
13+
for (const acc of FAKER.ACCOUNTS) {
14+
try {
15+
const createdAccount = await accountService.getByEmail(acc.email);
16+
if (!createdAccount) throw new Error('Account not found after creation');
17+
18+
const playlistsResponse = await playlistService.getManyPrivate(createdAccount.id);
19+
const playlists = playlistsResponse[0];
20+
21+
for (const playlist of playlists) {
22+
if (playlist) {
23+
for (let i = 0; i < 50; i++) {
24+
if (i % 3 === 0) {
25+
const item = await itemService.getRandomItem(playlist.medium_id);
26+
if (item) {
27+
await playlistResourceService.addItemToPlaylistFirst(playlist.id_text, item.id_text);
28+
}
29+
} else if (i % 3 === 1) {
30+
const clip = await clipService.getRandomClip(playlist.medium_id);
31+
if (clip) {
32+
await playlistResourceService.addClipToPlaylistFirst(playlist.id_text, clip.id_text);
33+
}
34+
} else {
35+
const itemSoundbite = await itemSoundbiteService.getRandomItemSoundbite(playlist.medium_id);
36+
if (itemSoundbite) {
37+
await playlistResourceService.addItemSoundbiteToPlaylistFirst(playlist.id_text, itemSoundbite.id_text);
38+
}
39+
}
40+
}
41+
}
42+
}
43+
} catch (err) {
44+
console.error(`Error creating queues:`, err);
45+
}
46+
}
47+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { AccountService, ClipService, ItemService, ItemSoundbiteService,
2+
QueueResourceService, QueueService} from 'podverse-orm';
3+
import { FAKER } from '../../constants';
4+
5+
export default async function () {
6+
const accountService = new AccountService();
7+
const clipService = new ClipService();
8+
const itemService = new ItemService();
9+
const itemSoundbiteService = new ItemSoundbiteService();
10+
const queueService = new QueueService();
11+
const queueResourceService = new QueueResourceService();
12+
13+
for (const acc of FAKER.ACCOUNTS) {
14+
try {
15+
const createdAccount = await accountService.getByEmail(acc.email);
16+
if (!createdAccount) throw new Error('Account not found after creation');
17+
18+
const queues = await queueService.getAllPrivate(createdAccount.id);
19+
for (const queue of queues) {
20+
if (queue) {
21+
for (let i = 0; i < 50; i++) {
22+
try {
23+
if (i % 3 === 0) {
24+
const item = await itemService.getRandomItem(queue.medium_id);
25+
if (item) {
26+
await queueResourceService.addItemToQueueNext(queue.id_text, item.id_text);
27+
}
28+
} else if (i % 3 === 1) {
29+
const clip = await clipService.getRandomClip(queue.medium_id);
30+
if (clip) {
31+
await queueResourceService.addClipToQueueNext(queue.id_text, clip.id_text);
32+
}
33+
} else {
34+
const itemSoundbite = await itemSoundbiteService.getRandomItemSoundbite(queue.medium_id);
35+
if (itemSoundbite) {
36+
await queueResourceService.addItemSoundbiteToQueueNext(queue.id_text, itemSoundbite.id_text);
37+
}
38+
}
39+
} catch (err) {
40+
console.log('Error adding to queue:', err);
41+
}
42+
}
43+
44+
for (let i = 0; i < 50; i++) {
45+
try {
46+
if (i % 3 === 0) {
47+
const item = await itemService.getRandomItem(queue.medium_id);
48+
if (item) {
49+
await queueResourceService.addItemToHistory(
50+
queue.id_text,
51+
item.id_text,
52+
{
53+
playback_position: (Math.floor(Math.random() * 600)).toString(),
54+
media_file_duration: (600 + Math.floor(Math.random() * 600)).toString(),
55+
completed: Math.random() < 0.5
56+
}
57+
);
58+
}
59+
} else if (i % 3 === 1) {
60+
const clip = await clipService.getRandomClip(queue.medium_id);
61+
if (clip) {
62+
await queueResourceService.addClipToHistory(
63+
queue.id_text,
64+
clip.id_text,
65+
{
66+
playback_position: (Math.floor(Math.random() * 300)).toString(),
67+
media_file_duration: (300 + Math.floor(Math.random() * 300)).toString(),
68+
completed: Math.random() < 0.5
69+
}
70+
);
71+
}
72+
} else {
73+
const itemSoundbite = await itemSoundbiteService.getRandomItemSoundbite(queue.medium_id);
74+
if (itemSoundbite) {
75+
await queueResourceService.addItemSoundbiteToHistory(
76+
queue.id_text,
77+
itemSoundbite.id_text,
78+
{
79+
playback_position: (Math.floor(Math.random() * 120)).toString(),
80+
media_file_duration: (120 + Math.floor(Math.random() * 120)).toString(),
81+
completed: Math.random() < 0.5
82+
}
83+
);
84+
}
85+
}
86+
} catch (err) {
87+
console.log('Error adding to history:', err);
88+
}
89+
}
90+
}
91+
}
92+
} catch (err) {
93+
console.error(`Error creating queues:`, err);
94+
}
95+
}
96+
}

src/faker/create/queues/queues.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { AccountService, QueueService } from 'podverse-orm';
2+
import { FAKER } from '../../constants';
3+
4+
export default async function () {
5+
const accountService = new AccountService();
6+
const queueService = new QueueService();
7+
8+
for (const acc of FAKER.ACCOUNTS) {
9+
try {
10+
const createdAccount = await accountService.getByEmail(acc.email);
11+
if (!createdAccount) throw new Error('Account not found after creation');
12+
13+
await queueService.getAllPrivate(createdAccount.id);
14+
} catch (err) {
15+
console.error(`Error creating queues:`, err);
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)