Skip to content

Commit 39e2a5b

Browse files
author
Ajit Kumar
committedFeb 22, 2025·
fix(plugin update version checking)
1 parent 15eb999 commit 39e2a5b

File tree

3 files changed

+85
-23
lines changed

3 files changed

+85
-23
lines changed
 

‎client/main.scss

+16-12
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ html {
1010
width: 100%;
1111
overflow: hidden;
1212
margin: 0;
13-
background: linear-gradient(
14-
to bottom,
15-
var(--secondary-color),
16-
var(--primary-color),
17-
var(--primary-color),
18-
var(--primary-color)
19-
);
13+
background: linear-gradient(to bottom,
14+
var(--secondary-color),
15+
var(--primary-color),
16+
var(--primary-color),
17+
var(--primary-color));
2018
color: var(--primary-text-color);
2119
font-family: 'Montserrat', sans-serif;
2220
}
@@ -89,9 +87,11 @@ body.loading {
8987
0% {
9088
transform: translateX(-100%) scaleX(0);
9189
}
90+
9291
50% {
9392
transform: translateX(100%) scaleX(1);
9493
}
94+
9595
100% {
9696
transform: translateX(100%) scaleX(0);
9797
}
@@ -108,7 +108,7 @@ header {
108108
position: sticky;
109109
top: 0;
110110

111-
> .icon {
111+
>.icon {
112112
height: 60px;
113113
width: 60px;
114114
display: flex;
@@ -142,7 +142,7 @@ header {
142142
justify-content: center;
143143
}
144144

145-
#menu-toggler ~ .mask {
145+
#menu-toggler~.mask {
146146
position: fixed;
147147
top: 0;
148148
left: 0;
@@ -153,11 +153,11 @@ header {
153153
transition: all 0.3s ease-in-out;
154154
}
155155

156-
#menu-toggler:checked ~ nav:nth-of-type(2) {
156+
#menu-toggler:checked~nav:nth-of-type(2) {
157157
transform: translateX(0);
158158
}
159159

160-
#menu-toggler:checked ~ .mask {
160+
#menu-toggler:checked~.mask {
161161
pointer-events: all;
162162
background-color: rgba($color: #000000, $alpha: 0.5);
163163
}
@@ -246,6 +246,7 @@ main {
246246
&:empty {
247247
position: relative;
248248
height: 100%;
249+
249250
&::before {
250251
position: absolute;
251252
top: 50%;
@@ -371,6 +372,7 @@ button {
371372
&:disabled,
372373
&.disabled {
373374
cursor: not-allowed;
375+
opacity: 0.5;
374376
}
375377

376378
&:hover {
@@ -387,10 +389,12 @@ button {
387389
background-color: var(--button-color);
388390
color: var(--button-text-color);
389391
}
392+
390393
50% {
391394
background-color: var(--button-hover-color);
392395
color: var(--button-text-color);
393396
}
397+
394398
100% {
395399
background-color: var(--button-color);
396400
color: var(--button-text-color);
@@ -437,4 +441,4 @@ code {
437441
[role='button'] {
438442
cursor: pointer;
439443
width: fit-content;
440-
}
444+
}

‎client/pages/publishPlugin/index.js

+52-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from 'lib/helpers';
66
import AjaxForm from 'components/ajaxForm';
77
import Router from 'lib/Router';
8+
import Ref from 'html-tag-js/ref';
89

910
export default async function PublishPlugin({ mode = 'publish', id }) {
1011
const user = await getLoggedInUser();
@@ -26,6 +27,7 @@ export default async function PublishPlugin({ mode = 'publish', id }) {
2627
const minVersionCode = <></>;
2728
const method = mode === 'publish' ? 'post' : 'put';
2829
const buttonText = <>{capitalize(mode)}</>;
30+
const submitButton = new Ref();
2931
const pluginIcon = <img style={{ height: '120px', width: '120px' }} src="#" alt="Plugin icon" />;
3032

3133
let plugin;
@@ -93,7 +95,9 @@ export default async function PublishPlugin({ mode = 'publish', id }) {
9395
</tbody>
9496
</table>
9597

96-
<button type='submit'> <span className="icon publish"></span> {buttonText}</button>
98+
<button ref={submitButton} type='submit'>
99+
<span className="icon publish"></span>{buttonText}
100+
</button>
97101
</AjaxForm>
98102
</section>;
99103

@@ -104,6 +108,7 @@ export default async function PublishPlugin({ mode = 'publish', id }) {
104108
}
105109

106110
successText.value = 'Plugin published successfully.';
111+
Router.loadUrl(`/plugin/${data.id}`);
107112
}
108113

109114
function onerror(error) {
@@ -140,6 +145,14 @@ export default async function PublishPlugin({ mode = 'publish', id }) {
140145
return;
141146
}
142147

148+
if (id && !isVersionGreater(manifest.version, plugin.version)) {
149+
submitButton.el.disabled = true;
150+
errorText.value = 'Version should be greater than previous version.';
151+
return;
152+
}
153+
154+
errorText.value = '';
155+
submitButton.el.disabled = false;
143156
pluginId.value = manifest.id;
144157
pluginName.value = manifest.name;
145158
pluginVersion.value = manifest.version;
@@ -155,4 +168,42 @@ export default async function PublishPlugin({ mode = 'publish', id }) {
155168

156169
reader.readAsArrayBuffer(file);
157170
}
171+
172+
function isVersionGreater(newV, oldV) {
173+
const [newMajor, newMinor, newPatch] = newV.split('.').map(Number);
174+
const [oldMajor, oldMinor, oldPatch] = oldV.split('.').map(Number);
175+
176+
if (newMajor > oldMajor) {
177+
return true;
178+
}
179+
180+
if (newMajor === oldMajor && newMinor > oldMinor) {
181+
return true;
182+
}
183+
184+
if (newMajor === oldMajor && newMinor === oldMinor && newPatch > oldPatch) {
185+
return true;
186+
}
187+
188+
return false;
189+
}
190+
191+
function getUpdateType(newV, oldV) {
192+
const [newMajor, newMinor, newPatch] = newV.split('.').map(Number);
193+
const [oldMajor, oldMinor, oldPatch] = oldV.split('.').map(Number);
194+
195+
if (newMajor > oldMajor) {
196+
return 'major';
197+
}
198+
199+
if (newMajor === oldMajor && newMinor > oldMinor) {
200+
return 'minor';
201+
}
202+
203+
if (newMajor === oldMajor && newMinor === oldMinor && newPatch > oldPatch) {
204+
return 'patch';
205+
}
206+
207+
return 'unknown';
208+
}
158209
}

‎server/apis/plugin.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ router.put('/', async (req, res) => {
459459
}
460460

461461
const { license, contributors, changelogs, keywords } = req.body;
462-
const { pluginJson, icon, readme } = await exploreZip(pluginZip.data);
462+
const { pluginJson, icon, readme, changelogs: changelogsFile } = await exploreZip(pluginZip.data);
463463

464464
const errorMessage = validatePlugin(pluginJson, icon, readme);
465465
if (errorMessage) {
@@ -492,7 +492,7 @@ router.put('/', async (req, res) => {
492492
[Plugin.DESCRIPTION, readme],
493493
[Plugin.LICENSE, license],
494494
[Plugin.CONTRIBUTORS, contributors],
495-
[Plugin.CHANGELOGS, changelogs],
495+
[Plugin.CHANGELOGS, changelogs || changelogsFile],
496496
[Plugin.KEYWORDS, keywords],
497497
];
498498

@@ -617,8 +617,9 @@ async function exploreZip(file) {
617617
const pluginJson = JSON.parse(await zip.file('plugin.json')?.async('string'));
618618
const icon = await zip.file('icon.png')?.async('base64');
619619
const readme = await zip.file('readme.md')?.async('string');
620+
const changelogs = await zip.file('changelogs.md')?.async('string');
620621

621-
return { pluginJson, icon, readme };
622+
return { pluginJson, icon, readme, changelogs };
622623
}
623624

624625
function savePlugin(id, file, icon) {
@@ -729,14 +730,20 @@ function isValidPrice(price) {
729730
return price && !Number.isNaN(price) && price >= MIN_PRICE && price <= MAX_PRICE;
730731
}
731732

732-
function isVersionGreater(v1, v2) {
733-
const v1Arr = v1.split('.');
734-
const v2Arr = v2.split('.');
733+
function isVersionGreater(newV, oldV) {
734+
const [newMajor, newMinor, newPatch] = newV.split('.').map(Number);
735+
const [oldMajor, oldMinor, oldPatch] = oldV.split('.').map(Number);
735736

736-
for (let i = 0; i < 3; i++) {
737-
if (v1Arr[i] > v2Arr[i]) {
738-
return true;
739-
}
737+
if (newMajor > oldMajor) {
738+
return true;
739+
}
740+
741+
if (newMajor === oldMajor && newMinor > oldMinor) {
742+
return true;
743+
}
744+
745+
if (newMajor === oldMajor && newMinor === oldMinor && newPatch > oldPatch) {
746+
return true;
740747
}
741748

742749
return false;

0 commit comments

Comments
 (0)
Please sign in to comment.