Skip to content

Commit

Permalink
[translation util] some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
drive4ik committed Jun 25, 2024
1 parent d1c56d5 commit 9447dc8
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions translate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
}

async function load(url, defaultValue = {}) {
let blob = await fetch(url),
result = await blob.json();
try {
const blob = await fetch(url);

if (!blob.ok) {
notify(`GitHub error: ${blob.status} ${blob.statusText}. Please wait a few minutes and try again.\n${result.message}`);
result = defaultValue;
}
if (!blob.ok) {
notify(`GitHub error: ${blob.status} ${blob.statusText}. Please wait a few minutes and try again.\n${result.message}`);
throw blob;
}

return result;
return await blob.json();
} catch (e) {
return defaultValue;
}
}

new Vue({
Expand Down Expand Up @@ -135,7 +138,16 @@
methods: {
async init() {
let plugins = await load(this.pluginsApiUrl, []);
this.components = [this.components[0]].concat(plugins.filter(element => 'dir' === element.type));

plugins = plugins.filter(element => {
if ('dir' !== element.type) {
return false;
}

return ['simple-', 'stg-'].some(str => element.name.startsWith(str));
});

this.components = [this.components[0], ...plugins];

await this.loadComponentData();
},
Expand Down

0 comments on commit 9447dc8

Please sign in to comment.