mirror of
https://github.com/janishutz/MusicPlayerV2.git
synced 2025-11-25 04:54:23 +00:00
some progress, interrupted because MusicKit bugs
This commit is contained in:
5
backend/config/apple-music-api.config.json
Normal file
5
backend/config/apple-music-api.config.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"teamID": "",
|
||||
"keyID": "",
|
||||
"storefront": "us"
|
||||
}
|
||||
48
backend/dist/app.js
vendored
Normal file
48
backend/dist/app.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = __importDefault(require("express"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
||||
const cors_1 = __importDefault(require("cors"));
|
||||
if (typeof (__dirname) === 'undefined') {
|
||||
__dirname = path_1.default.resolve(path_1.default.dirname(''));
|
||||
}
|
||||
const run = () => {
|
||||
let app = (0, express_1.default)();
|
||||
app.use((0, cors_1.default)({
|
||||
credentials: true,
|
||||
origin: true
|
||||
}));
|
||||
app.get('/', (request, response) => {
|
||||
response.send('HELLO WORLD');
|
||||
});
|
||||
app.get('/getAppleMusicDevToken', (req, res) => {
|
||||
// sign dev token
|
||||
const privateKey = fs_1.default.readFileSync(path_1.default.join(__dirname + '/config/apple_private_key.p8')).toString();
|
||||
// TODO: Remove secret
|
||||
const config = JSON.parse('' + fs_1.default.readFileSync(path_1.default.join(__dirname + '/config/apple-music-api.config.json')));
|
||||
const jwtToken = jsonwebtoken_1.default.sign({}, privateKey, {
|
||||
algorithm: "ES256",
|
||||
expiresIn: "180d",
|
||||
issuer: config.teamID,
|
||||
header: {
|
||||
alg: "ES256",
|
||||
kid: config.keyID
|
||||
}
|
||||
});
|
||||
res.send(jwtToken);
|
||||
});
|
||||
app.use((request, response, next) => {
|
||||
response.status(404).send('ERR_NOT_FOUND');
|
||||
// response.sendFile( path.join( __dirname + '' ) )
|
||||
});
|
||||
const PORT = process.env.PORT || 8081;
|
||||
app.listen(PORT);
|
||||
};
|
||||
exports.default = {
|
||||
run
|
||||
};
|
||||
1
backend/dist/config
vendored
Symbolic link
1
backend/dist/config
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../config/
|
||||
2
backend/index.js
Normal file
2
backend/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
const app = require( './dist/app.js' ).default;
|
||||
app.run();
|
||||
1043
backend/package-lock.json
generated
Normal file
1043
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
32
backend/package.json
Normal file
32
backend/package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "musicplayer-v2-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "The backend for MusicPlayerV2",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/simplePCBuilding/MusicPlayerV2.git"
|
||||
},
|
||||
"author": "Janis Hutz",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://github.com/simplePCBuilding/MusicPlayerV2/issues"
|
||||
},
|
||||
"homepage": "https://github.com/simplePCBuilding/MusicPlayerV2#readme",
|
||||
"devDependencies": {
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/body-parser": "^1.19.5",
|
||||
"@types/cors": "^2.8.17",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/jsonwebtoken": "^9.0.6",
|
||||
"body-parser": "^1.20.2",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.19.2",
|
||||
"jsonwebtoken": "^9.0.2"
|
||||
}
|
||||
}
|
||||
54
backend/src/app.ts
Normal file
54
backend/src/app.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import bodyParser from 'body-parser';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import cors from 'cors';
|
||||
|
||||
declare let __dirname: string | undefined
|
||||
if ( typeof( __dirname ) === 'undefined' ) {
|
||||
__dirname = path.resolve( path.dirname( '' ) );
|
||||
}
|
||||
|
||||
const run = () => {
|
||||
let app = express();
|
||||
app.use( cors( {
|
||||
credentials: true,
|
||||
origin: true
|
||||
} ) );
|
||||
|
||||
app.get( '/', ( request, response ) => {
|
||||
response.send( 'HELLO WORLD' );
|
||||
} );
|
||||
|
||||
|
||||
app.get( '/getAppleMusicDevToken', ( req, res ) => {
|
||||
// sign dev token
|
||||
const privateKey = fs.readFileSync( path.join( __dirname + '/config/apple_private_key.p8' ) ).toString();
|
||||
// TODO: Remove secret
|
||||
const config = JSON.parse( '' + fs.readFileSync( path.join( __dirname + '/config/apple-music-api.config.json' ) ) );
|
||||
const jwtToken = jwt.sign( {}, privateKey, {
|
||||
algorithm: "ES256",
|
||||
expiresIn: "180d",
|
||||
issuer: config.teamID,
|
||||
header: {
|
||||
alg: "ES256",
|
||||
kid: config.keyID
|
||||
}
|
||||
} );
|
||||
res.send( jwtToken );
|
||||
} );
|
||||
|
||||
app.use( ( request: express.Request, response: express.Response, next: express.NextFunction ) => {
|
||||
response.status( 404 ).send( 'ERR_NOT_FOUND' );
|
||||
// response.sendFile( path.join( __dirname + '' ) )
|
||||
} );
|
||||
|
||||
|
||||
const PORT = process.env.PORT || 8081;
|
||||
app.listen( PORT );
|
||||
}
|
||||
|
||||
export default {
|
||||
run
|
||||
}
|
||||
13
backend/tsconfig.json
Normal file
13
backend/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"allowJs": true,
|
||||
"target": "ES6",
|
||||
"skipLibCheck": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"types": ["node"],
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext"
|
||||
},
|
||||
"include": [ "./src/**/*" ],
|
||||
}
|
||||
Reference in New Issue
Block a user