Skip to content

Commit 973c0fc

Browse files
Merge pull request #7 from UnschooledGamer/fix/no-errorMsg--no-plugin-icon
add: error msgs when no plugin is present
1 parent b54aa54 commit 973c0fc

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

client/pages/publishPlugin/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export default async function PublishPlugin({ mode = 'publish', id }) {
140140

141141
function onerror(error) {
142142
errorText.value = error;
143+
submitButton.el.disabled = true;
144+
submitButton.el.ariaDisabled = true;
143145
}
144146

145147
function onFileChange() {
@@ -155,27 +157,35 @@ export default async function PublishPlugin({ mode = 'publish', id }) {
155157
pluginPrice.value = '';
156158
pluginIcon.src = '#';
157159
minVersionCode.value = '';
160+
submitButton.el.disabled = true;
161+
submitButton.el.ariaDisabled = true;
158162
return;
159163
}
160164

161165
const reader = new FileReader();
166+
submitButton.el.disabled = false;
167+
submitButton.el.ariaDisabled = false;
162168

163169
reader.onload = async () => {
164170
showLoading();
165171
const zip = await jsZip.loadAsync(reader.result);
166172
try {
167173
const manifest = JSON.parse(await zip.file('plugin.json').async('string'));
168-
const icon = await zip.file('icon.png').async('base64');
174+
const iconFileFromManifest = manifest?.icon || 'icon.png';
175+
const icon = await zip.file(iconFileFromManifest)?.async('base64');
169176

170177
if (id && id !== manifest.id) {
171178
throw new Error('Plugin ID is not same as previous version.');
172179
}
173180

174181
if (id && !isVersionGreater(manifest.version, plugin.version)) {
175182
submitButton.el.disabled = true;
183+
submitButton.el.ariaDisabled = true;
176184
throw new Error('Version should be greater than previous version.');
177185
}
178186

187+
if (!icon) errorText.value = 'Unable to load plugin icon: no icon was provided or the default icon (icon.png) is missing.';
188+
179189
const changelogs = (await zip.file('changelogs.md')?.async('string')) || (await zip.file('changelog.md')?.async('string'));
180190

181191
if (changelogs) {
@@ -220,6 +230,12 @@ export default async function PublishPlugin({ mode = 'publish', id }) {
220230
pluginName.value = manifest.name;
221231
pluginVersion.value = manifest.version;
222232
minVersionCode.value = manifest.minVersionCode || -1;
233+
// Checking for icon before rendering
234+
if (!icon) {
235+
submitButton.el.disabled = true;
236+
submitButton.el.ariaDisabled = true;
237+
throw new Error('Unable to load plugin icon: no icon was provided or the default icon (icon.png) is missing.');
238+
}
223239
pluginIcon.src = `data:image/png;base64,${icon}`;
224240

225241
errorText.value = '';

server/apis/plugin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ async function exploreZip(file) {
665665
const iconFile = zip.file(iconPath);
666666
let icon = null;
667667
if (iconFile) {
668-
icon = await iconFile.async('base64');
668+
icon = await iconFile?.async('base64');
669669
} else if (iconPath !== 'icon.png') {
670670
// If custom path failed, try the default path
671671
const defaultIconFile = zip.file('icon.png');
@@ -720,6 +720,10 @@ function validatePlugin(json, icon, readmeFile) {
720720
throw new Error('Missing readme.md file.');
721721
}
722722

723+
if (!icon) {
724+
throw new Error('Unable to load plugin icon: no icon was provided or the default icon (icon.png) is missing.');
725+
}
726+
723727
const { name, version, main, license, contributors, keywords } = json;
724728
const id = json.id.toLowerCase();
725729

0 commit comments

Comments
 (0)