Skip to content

Commit 4924b3e

Browse files
committed
Merge branch 'unit-testing' into develop
2 parents c9f3eaa + c258ad0 commit 4924b3e

File tree

21 files changed

+407
-66
lines changed

21 files changed

+407
-66
lines changed

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/song-browser/song-browser.controller.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Controller, Get, Param, Query } from '@nestjs/common';
1+
import {
2+
BadRequestException,
3+
Controller,
4+
Get,
5+
Param,
6+
Query,
7+
} from '@nestjs/common';
28
import { ApiOperation, ApiTags } from '@nestjs/swagger';
39
import { PageQueryDTO } from '@shared/validation/common/dto/PageQuery.dto';
410
import { FeaturedSongsDto } from '@shared/validation/song/dto/FeaturedSongsDto.dtc';
@@ -42,4 +48,19 @@ export class SongBrowserController {
4248
): Promise<SongPreviewDto[]> {
4349
return await this.songBrowserService.getSongsByCategory(id, query);
4450
}
51+
52+
@Get('/random')
53+
@ApiOperation({ summary: 'Get a list of songs at random' })
54+
public async getRandomSongs(
55+
@Query('count') count: string,
56+
@Query('category') category: string,
57+
): Promise<SongPreviewDto[]> {
58+
const countInt = parseInt(count);
59+
60+
if (isNaN(countInt) || countInt < 1 || countInt > 10) {
61+
throw new BadRequestException('Invalid query parameters');
62+
}
63+
64+
return await this.songBrowserService.getRandomSongs(countInt, category);
65+
}
4566
}

server/src/song-browser/song-browser.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,11 @@ export class SongBrowserService {
115115
query.limit ?? 10,
116116
);
117117
}
118+
119+
public async getRandomSongs(
120+
count: number,
121+
category: string,
122+
): Promise<SongPreviewDto[]> {
123+
return await this.songService.getRandomSongs(count, category);
124+
}
118125
}

server/src/song/song.service.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,33 @@ export class SongService {
436436
return songs.map((song) => SongPreviewDto.fromSongDocumentWithUser(song));
437437
}
438438

439+
public async getRandomSongs(
440+
count: number,
441+
category: string,
442+
): Promise<SongPreviewDto[]> {
443+
const songs = (await this.songModel
444+
.aggregate([
445+
{
446+
$match: {
447+
visibility: 'public',
448+
},
449+
},
450+
{
451+
$sample: {
452+
size: count,
453+
},
454+
},
455+
])
456+
.exec()) as unknown as SongWithUser[];
457+
458+
await this.songModel.populate(songs, {
459+
path: 'uploader',
460+
select: 'username profileImage -_id',
461+
});
462+
463+
return songs.map((song) => SongPreviewDto.fromSongDocumentWithUser(song));
464+
}
465+
439466
public async getAllSongs() {
440467
return this.songModel.find({});
441468
}

shared/features/song/obfuscate.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export class SongObfuscator {
3333
private copyMetaAndStats(song: Song, output: Song) {
3434
output.meta.name = song.meta.name;
3535
output.meta.author = song.meta.author;
36+
output.meta.originalAuthor = song.meta.originalAuthor;
3637
output.meta.description = song.meta.description;
38+
output.meta.importName = song.meta.importName;
3739

3840
output.loop.enabled = song.loop.enabled;
3941
output.loop.startTick = song.loop.startTick;

shared/validation/song/constants.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const UploadConst = deepFreeze({
4444
},
4545

4646
license: {
47-
default: 'cc_by',
47+
default: 'none',
4848
},
4949

5050
customInstruments: {
@@ -89,17 +89,21 @@ export const UploadConst = deepFreeze({
8989
},
9090

9191
licenses: {
92-
cc_by_sa: {
93-
name: 'Creative Commons - Attribution-ShareAlike 4.0',
94-
shortName: 'CC BY-SA 4.0',
95-
description:
96-
'You can copy, modify, and distribute this song, even for commercial purposes, as long as you credit the author and provide a link to the song. If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.\n\nFor more information, please visit the [Creative Commons website](https://creativecommons.org/licenses/by-sa/4.0/).',
97-
},
9892
standard: {
9993
name: 'Standard License',
10094
shortName: 'Standard License',
10195
description:
10296
"The author reserves all rights. You may not use this song without the author's permission.",
97+
uploadDescription:
98+
'You allow us to distribute your song on Note Block World. Other users can listen to it, but they cannot use the song without your permission.',
99+
},
100+
cc_by_sa: {
101+
name: 'Creative Commons - Attribution-ShareAlike 4.0',
102+
shortName: 'CC BY-SA 4.0',
103+
description:
104+
'You can copy, modify, and distribute this song, even for commercial purposes, as long as you credit the author and provide a link to the song. If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.\n\nFor more information, please visit the [Creative Commons website](https://creativecommons.org/licenses/by-sa/4.0/).',
105+
uploadDescription:
106+
'Anyone can copy, modify, remix, adapt and distribute this song, even for commercial purposes, as long as attribution is provided and the modifications are distributed under the same license.\nFor more information, visit the [Creative Commons](https://creativecommons.org/licenses/by-sa/4.0/) website.',
103107
},
104108
},
105109

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"react-infinite-scroll-component": "^6.1.0",
4848
"react-loading-skeleton": "^3.4.0",
4949
"react-markdown": "^9.0.1",
50+
"schema-dts": "^1.1.2",
5051
"sharp": "^0.33.4",
5152
"tailwind-merge": "^2.2.1",
5253
"tailwindcss": "3.4.1",

web/public/ads.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google.com, pub-2486912467787383, DIRECT, f08c47fec0942fa0

web/src/app/layout.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import NextTopLoader from 'nextjs-toploader';
77
import { Toaster } from 'react-hot-toast';
88
import 'react-loading-skeleton/dist/skeleton.css';
99
import { SkeletonTheme } from 'react-loading-skeleton';
10+
import { WebSite, WithContext } from 'schema-dts';
1011

1112
import GoogleAdSense from '../modules/shared/components/GoogleAdSense';
1213
import { TooltipProvider } from '../modules/shared/components/tooltip';
@@ -18,7 +19,8 @@ const lato = Lato({
1819

1920
export const metadata: Metadata = {
2021
title: { template: '%s | Note Block World', default: '' },
21-
description: 'Discover, share and listen to note block music',
22+
description:
23+
'Discover, share and listen to note block music from all around the world',
2224
applicationName: 'Note Block World',
2325
keywords: ['note block', 'music', 'minecraft', 'nbs', 'note block studio'],
2426
openGraph: {
@@ -30,6 +32,15 @@ export const metadata: Metadata = {
3032
},
3133
};
3234

35+
const jsonLd: WithContext<WebSite> = {
36+
'@context': 'https://schema.org',
37+
'@type': 'WebSite',
38+
name: 'Note Block World',
39+
url: process.env.NEXT_PUBLIC_URL,
40+
description:
41+
'Discover, share and listen to note block music from all around the world',
42+
};
43+
3344
export default function RootLayout({
3445
children,
3546
}: {
@@ -40,6 +51,11 @@ export default function RootLayout({
4051
<html lang='en'>
4152
<head>
4253
<GoogleAdSense pId={process.env.NEXT_PUBLIC_ADSENSE_CLIENT} />
54+
{/* https://nextjs.org/docs/app/building-your-application/optimizing/metadata#json-ld */}
55+
<script
56+
type='application/ld+json'
57+
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
58+
/>
4359
<link
4460
rel='apple-touch-icon'
4561
sizes='180x180'

web/src/modules/browse/components/HomePageComponent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import LoadMoreButton from './client/LoadMoreButton';
1010
import { TimespanButtonGroup } from './client/TimespanButton';
1111
import SongCard from './SongCard';
1212
import SongCardGroup from './SongCardGroup';
13+
import { InterSectionAdSlot } from '../../shared/components/client/ads/AdSlots';
1314
import {
1415
Carousel,
1516
CarouselContent,
@@ -63,6 +64,8 @@ export const HomePageComponent = () => {
6364
</>
6465
)}
6566

67+
<InterSectionAdSlot />
68+
6669
{/* RECENT SONGS */}
6770
<div className='flex flex-row flex-wrap justify-between items-center gap-4 mb-2'>
6871
<h2 className='text-xl uppercase z-[2]'>Recent songs</h2>

0 commit comments

Comments
 (0)