docs: updated swagger docs for player and legacy

This commit is contained in:
Rick van Lieshout 2024-06-25 09:46:45 +02:00
parent 403354186e
commit 22b4668639
5 changed files with 380 additions and 62 deletions

View File

@ -29,12 +29,13 @@ export const addPlaybackControl = (expressApp: Router, mainWindow: BrowserWindow
if (settingsStore.get(settings.playBackControl)) { if (settingsStore.get(settings.playBackControl)) {
/** /**
* @swagger * @swagger
* /play: * /player/play:
* get: * post:
* summary: Play action * summary: Play the current media
* tags: [player]
* responses: * responses:
* 200: * 200:
* description: Action performed * description: Ok
* content: * content:
* text/plain: * text/plain:
* schema: * schema:
@ -44,12 +45,13 @@ export const addPlaybackControl = (expressApp: Router, mainWindow: BrowserWindow
/** /**
* @swagger * @swagger
* /favorite/toggle: * /player/favorite/toggle:
* post: * post:
* summary: Toggle favorite * summary: Add the current media to your favorites, or remove it if its already added to your favorites
* tags: [player]
* responses: * responses:
* 200: * 200:
* description: Action performed * description: Ok
* content: * content:
* text/plain: * text/plain:
* schema: * schema:
@ -59,12 +61,13 @@ export const addPlaybackControl = (expressApp: Router, mainWindow: BrowserWindow
/** /**
* @swagger * @swagger
* /pause: * /player/pause:
* get: * post:
* summary: Pause action * summary: Pause the current media
* tags: [player]
* responses: * responses:
* 200: * 200:
* description: Action performed * description: Ok
* content: * content:
* text/plain: * text/plain:
* schema: * schema:
@ -74,12 +77,13 @@ export const addPlaybackControl = (expressApp: Router, mainWindow: BrowserWindow
/** /**
* @swagger * @swagger
* /next: * /player/next:
* get: * post:
* summary: Next action * summary: Play the next song
* tags: [player]
* responses: * responses:
* 200: * 200:
* description: Action performed * description: Ok
* content: * content:
* text/plain: * text/plain:
* schema: * schema:
@ -89,12 +93,13 @@ export const addPlaybackControl = (expressApp: Router, mainWindow: BrowserWindow
/** /**
* @swagger * @swagger
* /previous: * /player/previous:
* get: * post:
* summary: Previous action * summary: Play the previous song
* tags: [player]
* responses: * responses:
* 200: * 200:
* description: Action performed * description: Ok
* content: * content:
* text/plain: * text/plain:
* schema: * schema:
@ -102,17 +107,47 @@ export const addPlaybackControl = (expressApp: Router, mainWindow: BrowserWindow
*/ */
createPlayerAction("/previous", globalEvents.previous); createPlayerAction("/previous", globalEvents.previous);
/**
* @swagger
* /player/shuffle/toggle:
* post:
* summary: Play the previous song
* tags: [player]
* responses:
* 200:
* description: Ok
* content:
* text/plain:
* schema:
* $ref: '#/components/schemas/OkResponse'
*/
createPlayerAction("/shuffle/toggle", globalEvents.toggleShuffle); createPlayerAction("/shuffle/toggle", globalEvents.toggleShuffle);
/**
* @swagger
* /player/repeat/toggle:
* post:
* summary: Toggle the repeat status, toggles between "off" , "single" and "all"
* tags: [player]
* responses:
* 200:
* description: Ok
* content:
* text/plain:
* schema:
* $ref: '#/components/schemas/OkResponse'
*/
createPlayerAction("/repeat/toggle", globalEvents.toggleRepeat); createPlayerAction("/repeat/toggle", globalEvents.toggleRepeat);
/** /**
* @swagger * @swagger
* /playpause: * /player/playpause:
* get: * post:
* summary: Toggle play/pause * summary: Start playing the media if paused, or pause the media if playing
* tags: [player]
* responses: * responses:
* 200: * 200:
* description: Action performed * description: Ok
* content: * content:
* text/plain: * text/plain:
* schema: * schema:

View File

@ -18,6 +18,7 @@ export const addLegacyApi = (expressApp: Router, mainWindow: BrowserWindow) => {
* /image: * /image:
* get: * get:
* summary: Get current image * summary: Get current image
* tags: [legacy]
* deprecated: true * deprecated: true
* responses: * responses:
* 200: * 200:
@ -36,13 +37,108 @@ export const addLegacyApi = (expressApp: Router, mainWindow: BrowserWindow) => {
addLegacyControls(); addLegacyControls();
} }
function addLegacyControls() { function addLegacyControls() {
/**
* @swagger
* /play:
* get:
* summary: Play the current media
* tags: [legacy]
* deprecated: true
* responses:
* 200:
* description: Action performed
* content:
* text/plain:
* schema:
* $ref: '#/components/schemas/OkResponse'
*/
expressApp.get("/play", ({ res }) => handleGlobalEvent(res, globalEvents.play)); expressApp.get("/play", ({ res }) => handleGlobalEvent(res, globalEvents.play));
/**
* @swagger
* /favorite/toggle:
* get:
* summary: Add the current media to your favorites, or remove it if its already added to your favorites
* tags: [legacy]
* deprecated: true
* responses:
* 200:
* description: Ok
* content:
* text/plain:
* schema:
* $ref: '#/components/schemas/OkResponse'
*/
expressApp.post("/favorite/toggle", (req, res) => expressApp.post("/favorite/toggle", (req, res) =>
handleGlobalEvent(res, globalEvents.toggleFavorite) handleGlobalEvent(res, globalEvents.toggleFavorite)
); );
/**
* @swagger
* /pause:
* get:
* summary: Pause the current media
* tags: [legacy]
* deprecated: true
* responses:
* 200:
* description: Ok
* content:
* text/plain:
* schema:
* $ref: '#/components/schemas/OkResponse'
*/
expressApp.get("/pause", (req, res) => handleGlobalEvent(res, globalEvents.pause)); expressApp.get("/pause", (req, res) => handleGlobalEvent(res, globalEvents.pause));
/**
* @swagger
* /next:
* get:
* summary: Play the next song
* tags: [legacy]
* deprecated: true
* responses:
* 200:
* description: Ok
* content:
* text/plain:
* schema:
* $ref: '#/components/schemas/OkResponse'
*/
expressApp.get("/next", (req, res) => handleGlobalEvent(res, globalEvents.next)); expressApp.get("/next", (req, res) => handleGlobalEvent(res, globalEvents.next));
/**
* @swagger
* /previous:
* get:
* summary: Play the previous song
* tags: [legacy]
* deprecated: true
* responses:
* 200:
* description: Ok
* content:
* text/plain:
* schema:
* $ref: '#/components/schemas/OkResponse'
*/
expressApp.get("/previous", (req, res) => handleGlobalEvent(res, globalEvents.previous)); expressApp.get("/previous", (req, res) => handleGlobalEvent(res, globalEvents.previous));
/**
* @swagger
* /playpause:
* get:
* summary: Toggle play/pause
* tags: [legacy]
* deprecated: true
* responses:
* 200:
* description: Ok
* content:
* text/plain:
* schema:
* $ref: '#/components/schemas/OkResponse'
*/
expressApp.get("/playpause", (req, res) => { expressApp.get("/playpause", (req, res) => {
if (mediaInfo.status === MediaStatus.playing) { if (mediaInfo.status === MediaStatus.playing) {
handleGlobalEvent(res, globalEvents.pause); handleGlobalEvent(res, globalEvents.pause);

View File

@ -62,29 +62,15 @@
} }
} }
}, },
"/play": { "/player/play": {
"get": {
"summary": "Play action",
"responses": {
"200": {
"description": "Action performed",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
},
"/favorite/toggle": {
"post": { "post": {
"summary": "Toggle favorite", "summary": "Play action",
"tags": [
"player"
],
"responses": { "responses": {
"200": { "200": {
"description": "Action performed", "description": "Ok",
"content": { "content": {
"text/plain": { "text/plain": {
"schema": { "schema": {
@ -96,12 +82,35 @@
} }
} }
}, },
"/pause": { "/player/favorite/toggle": {
"get": { "post": {
"summary": "Add the current song to your favorites, or remove it if its already added to your favorites",
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
},
"/player/pause": {
"post": {
"summary": "Pause action", "summary": "Pause action",
"tags": [
"player"
],
"responses": { "responses": {
"200": { "200": {
"description": "Action performed", "description": "Ok",
"content": { "content": {
"text/plain": { "text/plain": {
"schema": { "schema": {
@ -113,12 +122,15 @@
} }
} }
}, },
"/next": { "/player/next": {
"get": { "post": {
"summary": "Next action", "summary": "Play the next song",
"tags": [
"player"
],
"responses": { "responses": {
"200": { "200": {
"description": "Action performed", "description": "Ok",
"content": { "content": {
"text/plain": { "text/plain": {
"schema": { "schema": {
@ -130,12 +142,35 @@
} }
} }
}, },
"/previous": { "/player/previous": {
"get": { "post": {
"summary": "Play the previous song",
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
},
"/player/shuffle/toggle": {
"post": {
"summary": "Previous action", "summary": "Previous action",
"tags": [
"player"
],
"responses": { "responses": {
"200": { "200": {
"description": "Action performed", "description": "Ok",
"content": { "content": {
"text/plain": { "text/plain": {
"schema": { "schema": {
@ -147,12 +182,35 @@
} }
} }
}, },
"/playpause": { "/player/repeat/toggle": {
"get": { "post": {
"summary": "Toggle play/pause", "summary": "Toggle the repeat status, toggles between \"off\" , \"single\" and \"all\"",
"tags": [
"player"
],
"responses": { "responses": {
"200": { "200": {
"description": "Action performed", "description": "Ok",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
},
"/player/playpause": {
"post": {
"summary": "Toggle play/pause",
"tags": [
"player"
],
"responses": {
"200": {
"description": "Ok",
"content": { "content": {
"text/plain": { "text/plain": {
"schema": { "schema": {
@ -255,6 +313,9 @@
"/image": { "/image": {
"get": { "get": {
"summary": "Get current image", "summary": "Get current image",
"tags": [
"legacy"
],
"deprecated": true, "deprecated": true,
"responses": { "responses": {
"200": { "200": {
@ -273,6 +334,132 @@
} }
} }
} }
},
"/play": {
"get": {
"summary": "Play action",
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
"description": "Action performed",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
},
"/favorite/toggle": {
"get": {
"summary": "Add the current song to your favorites, or remove it if its already added to your favorites",
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
"description": "Ok",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
},
"/pause": {
"get": {
"summary": "Pause action",
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
"description": "Ok",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
},
"/next": {
"get": {
"summary": "Play the next song",
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
"description": "Ok",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
},
"/previous": {
"get": {
"summary": "Play the previous song",
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
"description": "Ok",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
},
"/playpause": {
"get": {
"summary": "Toggle play/pause",
"tags": [
"legacy"
],
"deprecated": true,
"responses": {
"200": {
"description": "Ok",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/OkResponse"
}
}
}
}
}
}
} }
}, },
"components": { "components": {

View File

@ -147,7 +147,7 @@
<p class="group__title">API</p> <p class="group__title">API</p>
<div class="group__description"> <div class="group__description">
<p> <p>
TIDAL Hi-Fi has a built-in web API to allow users to get current song information. TIDAL Hi-Fi has a built-in web API to allow users to get current media information.
You can optionally enable playback control as well. You can optionally enable playback control as well.
</p> </p>
</div> </div>
@ -246,7 +246,7 @@
<div class="group__option" class="hidden"> <div class="group__option" class="hidden">
<div class="group__description"> <div class="group__description">
<h4>Show song</h4> <h4>Show song</h4>
<p>Show the current song in the Discord client</p> <p>Show the current media in the Discord client</p>
</div> </div>
<label class="switch"> <label class="switch">
<input id="discord_show_song" type="checkbox" /> <input id="discord_show_song" type="checkbox" />

View File

@ -74,7 +74,7 @@ const elements = {
}, },
/** /**
* Get the icon of the current song * Get the icon of the current media
*/ */
getSongIcon: function () { getSongIcon: function () {
const figure = this.get("media"); const figure = this.get("media");
@ -90,7 +90,7 @@ const elements = {
}, },
/** /**
* returns an array of all artists in the current song * returns an array of all artists in the current media
* @returns {Array} artists * @returns {Array} artists
*/ */
getArtistsArray: function () { getArtistsArray: function () {
@ -195,7 +195,7 @@ function getUpdateFrequency() {
} }
/** /**
* Play or pause the current song * Play or pause the current media
*/ */
function playPause() { function playPause() {
const play = elements.get("play"); const play = elements.get("play");