sumba 2.39.0 → 2.41.0
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/extend/bajo/hook.js +9 -0
- package/extend/bajo/intl/en-US.json +8 -1
- package/extend/bajo/intl/id.json +8 -1
- package/extend/dobo/model.js +30 -1
- package/extend/dobo/model.json +0 -19
- package/extend/waibuDb/schema/download.js +8 -3
- package/extend/waibuMpa/route/your-stuff/download/get.js +7 -3
- package/index.js +53 -1
- package/lib/config.js +5 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +9 -0
package/extend/bajo/hook.js
CHANGED
|
@@ -267,6 +267,15 @@ async function hook () {
|
|
|
267
267
|
const routes = ['waibuAdmin:/site/x/site/*']
|
|
268
268
|
this.app.waibu.config.route.disabled.push(...routes)
|
|
269
269
|
}
|
|
270
|
+
}, {
|
|
271
|
+
name: 'dobo.sumbaDownload:afterRemoveRecord',
|
|
272
|
+
handler: async function (id, rec, options = {}) {
|
|
273
|
+
const { fs } = this.app.lib
|
|
274
|
+
try {
|
|
275
|
+
await fs.remove(rec.oldData.jobQueue.result.file)
|
|
276
|
+
} catch (err) {
|
|
277
|
+
}
|
|
278
|
+
}
|
|
270
279
|
}]
|
|
271
280
|
}
|
|
272
281
|
|
|
@@ -142,6 +142,12 @@
|
|
|
142
142
|
"x": "Cross-Site",
|
|
143
143
|
"misc": "Miscellaneous",
|
|
144
144
|
"populateRouteGuard": "Populate route guard",
|
|
145
|
+
"statusQueue": "Queue",
|
|
146
|
+
"statusMqueue": "Masohi Queue",
|
|
147
|
+
"statusProcessing": "Processing",
|
|
148
|
+
"statusComplete": "Complete",
|
|
149
|
+
"statusFail": "Fail",
|
|
150
|
+
"fileDownloadNA": "File download is no longer available, has been removed, expired or you don't have permission to access it",
|
|
145
151
|
"field": {
|
|
146
152
|
"currentPassword": "Current Password",
|
|
147
153
|
"newPassword": "New Password",
|
|
@@ -178,7 +184,8 @@
|
|
|
178
184
|
"allTeams": "All Teams?",
|
|
179
185
|
"condition": "Condition",
|
|
180
186
|
"hiddenFields": "Hide Fields",
|
|
181
|
-
"_immutable": "Immutable"
|
|
187
|
+
"_immutable": "Immutable",
|
|
188
|
+
"download": "Download"
|
|
182
189
|
},
|
|
183
190
|
"validation": {
|
|
184
191
|
"password": {
|
package/extend/bajo/intl/id.json
CHANGED
|
@@ -148,6 +148,12 @@
|
|
|
148
148
|
"x": "Antar Situs",
|
|
149
149
|
"misc": "Lain-lain",
|
|
150
150
|
"populateRouteGuard": "Isikan pelindung rute",
|
|
151
|
+
"statusQueue": "Antrian",
|
|
152
|
+
"statusMqueue": "Antrian Masohi",
|
|
153
|
+
"statusProcessing": "Sedang Diproses",
|
|
154
|
+
"statusComplete": "Selesai",
|
|
155
|
+
"statusFail": "Gagal",
|
|
156
|
+
"fileDownloadNA": "Unduhan file tidak lagi tersedia, telah dihapus, kedaluwarsa, atau Anda tidak memiliki izin untuk mengaksesnya",
|
|
151
157
|
"field": {
|
|
152
158
|
"currentPassword": "Kata Sandi Saat Ini",
|
|
153
159
|
"newPassword": "Kata Sandi Baru",
|
|
@@ -184,7 +190,8 @@
|
|
|
184
190
|
"allTeams": "Semua Tim?",
|
|
185
191
|
"condition": "Kondisi",
|
|
186
192
|
"hiddenFields": "Sembunyikan Kolom",
|
|
187
|
-
"_immutable": "Immutable"
|
|
193
|
+
"_immutable": "Immutable",
|
|
194
|
+
"download": "Unduh"
|
|
188
195
|
},
|
|
189
196
|
"validation": {
|
|
190
197
|
"password": {
|
package/extend/dobo/model.js
CHANGED
|
@@ -44,9 +44,38 @@ const routeGuard = {
|
|
|
44
44
|
options: { ...options }
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
const download = {
|
|
48
|
+
baseName: 'download',
|
|
49
|
+
properties: [
|
|
50
|
+
'description,,50,true',
|
|
51
|
+
'file,text,,,true',
|
|
52
|
+
'type,,20,true',
|
|
53
|
+
'jobQueue,object',
|
|
54
|
+
{
|
|
55
|
+
name: 'size',
|
|
56
|
+
type: 'integer',
|
|
57
|
+
default: 0,
|
|
58
|
+
index: true
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'download',
|
|
62
|
+
type: 'string',
|
|
63
|
+
virtual: true,
|
|
64
|
+
getValue: async function (val, rec) {
|
|
65
|
+
return rec.status === 'COMPLETE' ? 'download' : 'nA'
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
features: ['sumba:siteId', 'sumba:userId', 'dobo:createdAt', 'dobo:updatedAt', {
|
|
70
|
+
name: 'sumba:status',
|
|
71
|
+
default: 'QUEUE',
|
|
72
|
+
values: ['QUEUE', 'MQUEUE', 'PROCESSING', 'COMPLETE', 'FAIL']
|
|
73
|
+
}]
|
|
74
|
+
}
|
|
75
|
+
|
|
47
76
|
async function model () {
|
|
48
77
|
const { merge, cloneDeep } = this.app.lib._
|
|
49
|
-
return [{
|
|
78
|
+
return [download, {
|
|
50
79
|
baseName: 'attrib-guard',
|
|
51
80
|
properties: [
|
|
52
81
|
{
|
package/extend/dobo/model.json
CHANGED
|
@@ -17,25 +17,6 @@
|
|
|
17
17
|
"values": ["NEW", "ACK"]
|
|
18
18
|
}, "sumba:userId", "sumba:siteId", "dobo:createdAt", "dobo:updatedAt"
|
|
19
19
|
]
|
|
20
|
-
}, {
|
|
21
|
-
"baseName": "download",
|
|
22
|
-
"properties": [
|
|
23
|
-
"description,,50,true",
|
|
24
|
-
"file,text,,,true",
|
|
25
|
-
"type,,20,true",
|
|
26
|
-
"jobQueue,object",
|
|
27
|
-
{
|
|
28
|
-
"name": "size",
|
|
29
|
-
"type": "integer",
|
|
30
|
-
"default": 0,
|
|
31
|
-
"index": true
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
"features": ["sumba:siteId", "sumba:userId", "dobo:createdAt", "dobo:updatedAt", {
|
|
35
|
-
"name": "sumba:status",
|
|
36
|
-
"default": "INQUEUE",
|
|
37
|
-
"values": ["INQUEUE", "PROCESSING", "COMPLETE", "FAIL"]
|
|
38
|
-
}]
|
|
39
20
|
}, {
|
|
40
21
|
"baseName": "site-setting",
|
|
41
22
|
"properties": [
|
|
@@ -3,10 +3,15 @@ async function download () {
|
|
|
3
3
|
common: {
|
|
4
4
|
disabled: ['create', 'update', 'get'],
|
|
5
5
|
format: {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
download: async function (val, rec, { req } = {}) {
|
|
7
|
+
let sentence = req.t(val)
|
|
8
|
+
if (rec.status === 'COMPLETE') sentence = `<c:btn size="sm" icon="download" color="primary" href="sumba:/your-stuff/download/get/${rec.id}" content="${val}" @click.stop />`
|
|
8
9
|
return await this.component.buildSentence(sentence)
|
|
9
10
|
},
|
|
11
|
+
type: async function (val, rec, { req } = {}) {
|
|
12
|
+
const { camelCase } = this.app.lib._
|
|
13
|
+
return req.t(camelCase(`file ${val}`))
|
|
14
|
+
},
|
|
10
15
|
size: function (val, rec) {
|
|
11
16
|
const { formatByte } = this.app.bajoExtra
|
|
12
17
|
return formatByte(rec.size)
|
|
@@ -15,7 +20,7 @@ async function download () {
|
|
|
15
20
|
},
|
|
16
21
|
view: {
|
|
17
22
|
list: {
|
|
18
|
-
fields: ['description', 'type', 'size', 'status', 'updatedAt'],
|
|
23
|
+
fields: ['description', 'type', 'size', 'status', 'updatedAt', 'download'],
|
|
19
24
|
stat: {
|
|
20
25
|
aggregate: [
|
|
21
26
|
{ fields: ['type'], group: 'type', aggregate: ['count'] },
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
const get = {
|
|
2
2
|
method: ['GET'],
|
|
3
|
-
url: '/your-stuff/download/get
|
|
3
|
+
url: '/your-stuff/download/get/:id',
|
|
4
4
|
handler: async function (req, reply) {
|
|
5
5
|
const { importModule } = this.app.bajo
|
|
6
|
+
const { getModel } = this.app.dobo
|
|
7
|
+
const { fs } = this.app.lib
|
|
6
8
|
const { download } = await importModule('waibu:/lib/helper.js', { asDefaultImport: false })
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
+
const query = { id: req.params.id, siteId: req.site.id, userId: req.user.id, status: 'COMPLETE' }
|
|
10
|
+
const rec = await getModel('SumbaDownload').findOneRecord({ query }, { noMagic: true })
|
|
11
|
+
if (!rec || !fs.existsSync(rec.jobQueue.result.file)) throw this.error('fileDownloadNA', { forceShowMessage: true })
|
|
12
|
+
return await download.call(this, rec.jobQueue.result.file, req, reply, rec.file)
|
|
9
13
|
}
|
|
10
14
|
}
|
|
11
15
|
|
package/index.js
CHANGED
|
@@ -107,6 +107,10 @@ async function factory (pkgName) {
|
|
|
107
107
|
const user = await getModel('SumbaUser').findOneRecord({ query: { username: 'admin', siteId: site.id + '' } }, { noMagic: true })
|
|
108
108
|
this.config.xSiteAdmins.push(`${site.alias}:${user.username}`)
|
|
109
109
|
}
|
|
110
|
+
this._queueIntv = setInterval(() => {
|
|
111
|
+
this.execDownload()
|
|
112
|
+
}, this.config.queue.intvDur)
|
|
113
|
+
await this.execDownload()
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
/**
|
|
@@ -556,8 +560,22 @@ async function factory (pkgName) {
|
|
|
556
560
|
return passwd
|
|
557
561
|
}
|
|
558
562
|
|
|
559
|
-
|
|
563
|
+
/**
|
|
564
|
+
* Push a download job to the download manager
|
|
565
|
+
*
|
|
566
|
+
* @method
|
|
567
|
+
* @param {object} options - Options object
|
|
568
|
+
* @param {string} [options.description] - Description of the download. If not provided, the file name will be used as the description
|
|
569
|
+
* @param {string} options.worker - Worker handler
|
|
570
|
+
* @param {object} options.data - Data to be passed to the worker
|
|
571
|
+
* @param {string} options.source - Source of the job
|
|
572
|
+
* @param {object} options.req - Request object
|
|
573
|
+
* @param {string} options.file - File name
|
|
574
|
+
* @param {string} options.type - File type
|
|
575
|
+
*/
|
|
576
|
+
pushDownload = async (options = {}) => {
|
|
560
577
|
const { createRecord } = this.app.getPlugin('waibuDb')
|
|
578
|
+
let { description, worker, data, source, req, file, type } = options
|
|
561
579
|
description = description ?? file
|
|
562
580
|
const jobQueue = {
|
|
563
581
|
worker, // handler that gets executed by the worker
|
|
@@ -576,6 +594,39 @@ async function factory (pkgName) {
|
|
|
576
594
|
if (this.app.masohi) await this.app.masohi.pushJob(jobQueue)
|
|
577
595
|
}
|
|
578
596
|
|
|
597
|
+
/**
|
|
598
|
+
* Execute download job from the queue
|
|
599
|
+
* @async
|
|
600
|
+
* @method
|
|
601
|
+
* @returns {Promise<void>} - A promise that resolves when the download job has been executed
|
|
602
|
+
*/
|
|
603
|
+
execDownload = async () => {
|
|
604
|
+
const { isEmpty } = this.app.lib._
|
|
605
|
+
const { fs } = this.app.lib
|
|
606
|
+
const { callHandler } = this.app.bajo
|
|
607
|
+
const { getModel } = this.app.dobo
|
|
608
|
+
const { lock } = this.app.bajoExtra
|
|
609
|
+
const query = { status: 'QUEUE', sort: { createdAt: 1 } }
|
|
610
|
+
const model = getModel('SumbaDownload')
|
|
611
|
+
const rec = await model.findOneRecord({ query }, { noMagic: true, dataOnly: true })
|
|
612
|
+
if (isEmpty(rec)) return
|
|
613
|
+
const opts = { payload: { data: rec.jobQueue.payload.data } }
|
|
614
|
+
opts.payload.data.file = rec.file
|
|
615
|
+
const release = await lock(`sumba-download-${rec.id}`)
|
|
616
|
+
if (!release) return
|
|
617
|
+
try {
|
|
618
|
+
await model.updateRecord(rec.id, { status: 'PROCESSING' })
|
|
619
|
+
rec.jobQueue.result = await callHandler(rec.jobQueue.worker, opts)
|
|
620
|
+
const { size } = fs.statSync(rec.jobQueue.result.file)
|
|
621
|
+
await model.updateRecord(rec.id, { size, status: 'COMPLETE', jobQueue: rec.jobQueue })
|
|
622
|
+
} catch (err) {
|
|
623
|
+
rec.jobQueue.error = err.message
|
|
624
|
+
await model.updateRecord(rec.id, { status: 'FAIL', jobQueue: rec.jobQueue })
|
|
625
|
+
}
|
|
626
|
+
// TODO: notify user that the download is ready
|
|
627
|
+
await release()
|
|
628
|
+
}
|
|
629
|
+
|
|
579
630
|
/**
|
|
580
631
|
* Get API key from user ID by hashing the user's salt
|
|
581
632
|
*
|
|
@@ -1238,6 +1289,7 @@ async function factory (pkgName) {
|
|
|
1238
1289
|
const defSetting = {}
|
|
1239
1290
|
const nsSetting = {}
|
|
1240
1291
|
const names = this.app.getAllNs()
|
|
1292
|
+
names.push('bajo')
|
|
1241
1293
|
const query = {
|
|
1242
1294
|
ns: { $in: names },
|
|
1243
1295
|
siteId: site.id + ''
|
package/lib/config.js
CHANGED
|
@@ -53,6 +53,8 @@ export const defMultiSite = {
|
|
|
53
53
|
* @property {string} [config.auth.jwt.secret] - JWT authentication secret. Default: hard coded value, should be changed in production
|
|
54
54
|
* @property {string} [config.auth.jwt.expiresInDur='7d'] - JWT authentication token expiration duration. Default: '7d'
|
|
55
55
|
* @property {object} [config.redirect={}] - Redirection configuration object
|
|
56
|
+
* @property {object} [config.queue={}] - Internal Queue configuration object
|
|
57
|
+
* @property {string} [config.queue.intvDur='1m'] - Queue interval duration. Default: '1m'
|
|
56
58
|
*/
|
|
57
59
|
|
|
58
60
|
async function configFactory () {
|
|
@@ -169,7 +171,6 @@ async function configFactory () {
|
|
|
169
171
|
},
|
|
170
172
|
siteSetting: {
|
|
171
173
|
forgotPasswordExpDur: '5m',
|
|
172
|
-
timeZone: 'UTC',
|
|
173
174
|
userPassword: {
|
|
174
175
|
minUpperCase: 1,
|
|
175
176
|
minLowerCase: 1,
|
|
@@ -189,6 +190,9 @@ async function configFactory () {
|
|
|
189
190
|
getSiteDur: '1m',
|
|
190
191
|
getUserByIdDur: '1m',
|
|
191
192
|
getUserByTokenDur: '1m'
|
|
193
|
+
},
|
|
194
|
+
queue: {
|
|
195
|
+
intvDur: '1m'
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-07-29
|
|
4
|
+
|
|
5
|
+
- [2.41.0] Add `bajo` namespace to `getSite`
|
|
6
|
+
- [2.41.0] Remove `config.siteSetting.timeZone` and use default `timeZone` from `bajo` instead
|
|
7
|
+
|
|
8
|
+
## 2026-07-28
|
|
9
|
+
|
|
10
|
+
- [2.40.0] Add queue for `download` & all necessary methods to support it
|
|
11
|
+
|
|
3
12
|
## 2026-07-26
|
|
4
13
|
|
|
5
14
|
- [2.39.0] Rename `pushDownload()` to `download()`
|