Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Backend service for the Symfi application.
* `PORT`: (`number | undefined`) – port to run the server on
* `PROXY_DOWNLOAD_ENABLED`: (`true | undefined`) – enable proxy download
* `PROXY_DOWNLOAD_ORIGIN`: (`string | undefined`) – origin to proxy download
requests to
* `PROXY_DOWNLOAD_STREAM_ENDPOINT`: (`true | undefined`) – uses newer "/stream" endpoint for proxy download (requires PROXY_DOWNLOAD_ENABLED)

## License

Expand Down
61 changes: 56 additions & 5 deletions api/v3.0.0.yaml → api/v3.x.x.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ info:
name: MIT
url: https://opensource.org/licenses/MIT
title: Symfi API
version: 3.0.0
version: 3.1.0
servers:
- description: Development server
url: http://localhost:5000/
- description: Primary server
url: https://symfi-api.was.org.pl
paths:
/v3/ping:
get:
Expand All @@ -20,11 +22,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Success'
/v3/song/:id:
/v3/song/{id}:
get:
deprecated: true
description: Download a song by its id
parameters:
- name: songId
- name: id
in: path
required: true
schema:
Expand All @@ -34,7 +37,7 @@ paths:
'200':
description: Song found
content:
audio/mpeg3:
audio/webm:
schema:
format: binary
type: string
Expand All @@ -46,6 +49,7 @@ paths:
$ref: '#/components/responses/YouTubeError'
/v3/song/download:
get:
deprecated: true
description: Get the song download URL
parameters:
- name: id
Expand All @@ -67,6 +71,29 @@ paths:
$ref: '#/components/responses/NotFound'
'502':
$ref: '#/components/responses/YouTubeError'
/v3/song/meta/{id}:
get:
description: Get the song download URL
parameters:
- name: id
in: path
required: true
schema:
type: string
example: 'dQw4w9WgXcQ'
responses:
'200':
description: Success response with the song download URL in the meta field
content:
application/json:
schema:
$ref: '#/components/schemas/Success'
'400':
$ref: '#/components/responses/BadRequest'
'404':
$ref: '#/components/responses/NotFound'
'502':
$ref: '#/components/responses/YouTubeError'
/v3/song/search:
get:
description: Search for a song
Expand Down Expand Up @@ -102,6 +129,30 @@ paths:
$ref: '#/components/schemas/Error'
'502':
$ref: '#/components/responses/YouTubeError'
/v3/song/stream/{id}:
get:
description: Download a song by its id
parameters:
- name: id
in: path
required: true
schema:
type: string
example: 'dQw4w9WgXcQ'
responses:
'200':
description: Song found
content:
audio/webm:
schema:
format: binary
type: string
'400':
$ref: '#/components/responses/BadRequest'
'404':
$ref: '#/components/responses/NotFound'
'502':
$ref: '#/components/responses/YouTubeError'
/v3/song/suggestion:
get:
description: Get suggestions for songs
Expand Down Expand Up @@ -212,7 +263,7 @@ components:
id:
description: "YouTube video ID"
example: "dQw4w9WgXcQ"
type: integer
type: string
name:
description: "Song title"
example: "Never Gonna Give You Up"
Expand Down
17 changes: 3 additions & 14 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"files": {
"ignore": [
"package.json",
"package-lock.json"
],
"ignore": ["package.json", "package-lock.json"],
"include": ["**/*.ts", "**/*.json"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80
"lineWidth": 120
},
"javascript": {
"formatter": {
"arrowParentheses": "asNeeded",
"quoteStyle": "single"
},
"globals": [
"afterAll",
"beforeAll",
"beforeEach",
"describe",
"expect",
"it",
"jest"
]
"globals": ["afterAll", "beforeAll", "beforeEach", "describe", "expect", "it", "jest"]
},
"linter": {
"enabled": true,
Expand Down
27 changes: 20 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"express-validator": "^7.1.0",
"file-system-cache": "2.4.7",
"tsconfig-paths": "^4.2.0",
"youtubei.js": "10.4.0"
"youtubei.js": "^10.5.0"
},
"description": "",
"devDependencies": {
Expand Down
11 changes: 2 additions & 9 deletions src/controllers/v2/content.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ const checkIdsCorrectness = async (

try {
const data = mediaInfoPromises
.filter(
(promise): promise is PromiseFulfilledResult<VideoInfo> =>
promise.status === 'fulfilled',
)
.filter((promise): promise is PromiseFulfilledResult<VideoInfo> => promise.status === 'fulfilled')
.map(({ value }) => new VideoInfoToMediaInfoAdapter(value));

res.status(200).json(data);
Expand All @@ -38,11 +35,7 @@ const checkIdsCorrectness = async (
}
};

const streamAudio = async (
req: Request<{ id: string }>,
res: Response,
next: NextFunction,
) => {
const streamAudio = async (req: Request<{ id: string }>, res: Response, next: NextFunction) => {
// get resource id and path to resource if it is cached
const resourceID = decodeURI(req.params.id);
const cachedPath = cache.getSync(resourceID);
Expand Down
10 changes: 9 additions & 1 deletion src/controllers/v2/media.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ const getMediaURL = async (

// redirect request to the local endpoint that streams audio
if (process.env.PROXY_DOWNLOAD_ENABLED) {
const streamEndpointEnv = process.env.PROXY_DOWNLOAD_STREAM_ENDPOINT;
const hasCustomStreamEndpoint = streamEndpointEnv?.match(/true/i);

const origin = process.env.PROXY_DOWNLOAD_ORIGIN || `${req.protocol}://${req.get('host')}`;
const path = hasCustomStreamEndpoint ? `/v3/song/stream/${id}` : `/v3/song/${id}`;

const url = new URL(path, origin);

return res.status(200).json({
link: `${req.protocol}://${req.get('host')}/v2/content/youtube/${id}`,
link: url.href,
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/controllers/v2/search.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const searchThroughYouTube = async (
Record<string, never>,
MediaInfo[],
undefined,
{ query: string }
{
query: string;
}
>,
res: Response<MediaInfo[]>,
next: NextFunction,
Expand Down
Loading