plexsonic 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/plex.js +3 -1
- package/src/server.js +40 -0
- package/src/subsonic-xml.js +3 -1
- package/src/version.js +37 -0
package/README.md
CHANGED
package/package.json
CHANGED
package/src/plex.js
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* under the License.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import { APP_VERSION } from './version.js';
|
|
22
|
+
|
|
21
23
|
const PLEX_TV_BASE = 'https://plex.tv';
|
|
22
24
|
const PLEX_CLIENTS_BASE = 'https://clients.plex.tv';
|
|
23
25
|
|
|
@@ -25,7 +27,7 @@ function makePlexHeaders(config, token = null) {
|
|
|
25
27
|
const headers = {
|
|
26
28
|
Accept: 'application/json',
|
|
27
29
|
'X-Plex-Product': config.plexProduct,
|
|
28
|
-
'X-Plex-Version':
|
|
30
|
+
'X-Plex-Version': APP_VERSION,
|
|
29
31
|
'X-Plex-Client-Identifier': config.plexClientIdentifier,
|
|
30
32
|
'X-Plex-Platform': process.platform,
|
|
31
33
|
'X-Plex-Device': 'Plexsonic Bridge',
|
package/src/server.js
CHANGED
|
@@ -73,6 +73,39 @@ import { createTokenCipher } from './token-crypto.js';
|
|
|
73
73
|
import { emptyNode, failedResponse, failedResponseJson, node, okResponse, okResponseJson } from './subsonic-xml.js';
|
|
74
74
|
|
|
75
75
|
const USERNAME_PATTERN = /^[A-Za-z0-9_.-]{3,32}$/;
|
|
76
|
+
const DEFAULT_CORS_ALLOW_HEADERS = [
|
|
77
|
+
'Accept',
|
|
78
|
+
'Authorization',
|
|
79
|
+
'Content-Type',
|
|
80
|
+
'X-Requested-With',
|
|
81
|
+
'X-Plex-Token',
|
|
82
|
+
'X-Plex-Client-Identifier',
|
|
83
|
+
'X-Plex-Product',
|
|
84
|
+
'X-Plex-Version',
|
|
85
|
+
'X-Plex-Platform',
|
|
86
|
+
'X-Plex-Device',
|
|
87
|
+
'X-Plex-Device-Name',
|
|
88
|
+
'X-Plex-Model',
|
|
89
|
+
].join(', ');
|
|
90
|
+
const DEFAULT_CORS_ALLOW_METHODS = 'GET, POST, PUT, PATCH, DELETE, OPTIONS';
|
|
91
|
+
const DEFAULT_CORS_EXPOSE_HEADERS = 'content-type, content-length, content-range, accept-ranges, etag, last-modified';
|
|
92
|
+
|
|
93
|
+
function applyCorsHeaders(request, reply) {
|
|
94
|
+
const origin = firstForwardedValue(request.headers?.origin);
|
|
95
|
+
if (origin) {
|
|
96
|
+
reply.header('access-control-allow-origin', origin);
|
|
97
|
+
reply.header('vary', 'Origin');
|
|
98
|
+
} else {
|
|
99
|
+
reply.header('access-control-allow-origin', '*');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
reply.header('access-control-allow-methods', DEFAULT_CORS_ALLOW_METHODS);
|
|
103
|
+
|
|
104
|
+
const requestedHeaders = firstForwardedValue(request.headers?.['access-control-request-headers']);
|
|
105
|
+
reply.header('access-control-allow-headers', requestedHeaders || DEFAULT_CORS_ALLOW_HEADERS);
|
|
106
|
+
reply.header('access-control-expose-headers', DEFAULT_CORS_EXPOSE_HEADERS);
|
|
107
|
+
reply.header('access-control-max-age', '86400');
|
|
108
|
+
}
|
|
76
109
|
|
|
77
110
|
function normalizeUsername(value) {
|
|
78
111
|
return String(value || '').trim();
|
|
@@ -1981,6 +2014,13 @@ export async function buildServer(config = loadConfig()) {
|
|
|
1981
2014
|
},
|
|
1982
2015
|
});
|
|
1983
2016
|
|
|
2017
|
+
app.addHook('onRequest', async (request, reply) => {
|
|
2018
|
+
applyCorsHeaders(request, reply);
|
|
2019
|
+
if (request.method === 'OPTIONS') {
|
|
2020
|
+
return reply.code(204).send();
|
|
2021
|
+
}
|
|
2022
|
+
});
|
|
2023
|
+
|
|
1984
2024
|
app.addHook('onClose', async () => {
|
|
1985
2025
|
db.close();
|
|
1986
2026
|
});
|
package/src/subsonic-xml.js
CHANGED
|
@@ -18,11 +18,13 @@
|
|
|
18
18
|
* under the License.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
import { APP_VERSION } from './version.js';
|
|
22
|
+
|
|
21
23
|
const XML_HEADER = '<?xml version="1.0" encoding="UTF-8"?>';
|
|
22
24
|
const XMLNS = 'http://subsonic.org/restapi';
|
|
23
25
|
const API_VERSION = '1.16.1';
|
|
24
26
|
const SERVER_TYPE = 'Plexsonic';
|
|
25
|
-
const SERVER_VERSION =
|
|
27
|
+
const SERVER_VERSION = APP_VERSION;
|
|
26
28
|
const OPEN_SUBSONIC = true;
|
|
27
29
|
|
|
28
30
|
const TOKEN_START = '\u0001';
|
package/src/version.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* Copyright Yukino Song, SudoMaker Ltd.
|
|
2
|
+
*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { createRequire } from 'node:module';
|
|
22
|
+
|
|
23
|
+
const require = createRequire(import.meta.url);
|
|
24
|
+
|
|
25
|
+
function loadPackageVersion() {
|
|
26
|
+
try {
|
|
27
|
+
const packageJson = require('../package.json');
|
|
28
|
+
const rawVersion = String(packageJson?.version || '').trim();
|
|
29
|
+
if (rawVersion) {
|
|
30
|
+
return rawVersion;
|
|
31
|
+
}
|
|
32
|
+
} catch {}
|
|
33
|
+
|
|
34
|
+
return '0.0.0';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const APP_VERSION = loadPackageVersion();
|