Skip to content

Commit

Permalink
fix pomf upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rcc11 committed Apr 7, 2021
1 parent 2126f4f commit 1372f72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/components/settings/hosts.js
@@ -1,3 +1,12 @@
function validURL(value) {
try {
new URL(value.replace(/%s/, 'sound').replace(/^(https?\/\/)?/, 'https://'));
return true;
} catch (err) {
return false;
}
}

module.exports = {
template: require('./templates/host_input.tpl'),

Expand Down Expand Up @@ -29,12 +38,8 @@ module.exports = {
}

// Validate URL
if (changedField === 'url' || changedField === 'soundUrl') {
try {
(changedField === 'url' || newValue) && new URL(newValue);
} catch (err) {
throw new PlayerError('The value must be a valid URL.', 'warning');
}
if ((changedField === 'url' || changedField === 'soundUrl' && newValue) && !validURL(newValue)) {
throw new PlayerError('The value must be a valid URL.', 'warning');
}

// Parse the data
Expand Down Expand Up @@ -70,8 +75,8 @@ module.exports = {
const headersValue = container.querySelector('[name=headers]').value;
if (name
&& JSON.parse(container.querySelector('[name=data]').value)
&& new URL(container.querySelector('[name=url]').value)
&& (!soundUrlValue || new URL(soundUrlValue))
&& validURL(container.querySelector('[name=url]').value)
&& (!soundUrlValue || validURL(soundUrlValue))
&& (!headersValue || JSON.parse(headersValue))) {

delete host.invalid;
Expand All @@ -90,7 +95,7 @@ module.exports = {
const hosts = {
[`${name}${i}`]: { invalid: true, data: { file: '$file' } },
...Player.config.uploadHosts
}
};
Player.settings.set('uploadHosts', hosts, { bypassValidation: true, silent: true });
},

Expand Down
1 change: 1 addition & 0 deletions src/config/hosts.js
Expand Up @@ -35,6 +35,7 @@ module.exports = [
url: 'https://pomf.cat/upload.php',
data: { 'files[]': '$file' },
responsePath: 'files.0.url',
soundUrl: 'a.pomf.cat/%s',
filenameLength: 23
},
zz: {
Expand Down

0 comments on commit 1372f72

Please sign in to comment.