@samitouri / QOSami-HFS / commits / 821c835a

fix: (regression 0.49.0) unwanted plugin "." in list

Massimo Melina committed Sep 24, 2023 at 17:31 UTC 821c835aa866708bae4d16937f2c4a64dd56158f
2 files changed +8 -9
src/api.net.ts
+5 -6
@@ -261,16 +261,15 @@ events.once('https ready', () => repeat(HOUR, renewCert))
261
262 // checks if the cert is near expiration date, and if so renews it
263 const renewCert = debounceAsync(async () => {
264 - const acmeLog = (...args: any[]) => console.log('[acme-renew]:', ...args)
265 - const now = new Date()
264 const cert = getCertObject()
265 if (!cert) return
266 + const now = new Date()
267 const validTo = new Date(cert.validTo)
269 - const isValid = now > new Date(cert.validFrom) && now < validTo &&
270 - validTo.getTime() - now.getTime() >= 30 * DAY // it's not expiring in a month
271 - if (isValid) return acmeLog("certificate is good")
268 + // not expiring in a month
269 + if (now > new Date(cert.validFrom) && now < validTo && validTo.getTime() - now.getTime() >= 30 * DAY)
270 + return console.log("certificate still good")
271 await makeCert(acme_domain.get(), acme_email.get())
273 - .catch(e => acmeLog("error: ", e.toString()))
272 + .catch(e => console.log("error renewing certificate: ", String(e)))
273 }, 0, { retain: DAY, retainFailure: HOUR })
274
275 export default apis
\ No newline at end of file
src/plugins.ts
+3 -3
@@ -208,11 +208,12 @@ export class Plugin {
208 }
209 }
210
211 +const SERVER_CODE_ID = '.'
212 const serverCode = defineConfig('server_code', '', async (script, { k }) => {
213 const res: any = {}
214 try {
215 new Function('exports', script)(res) // parse
215 - return new Plugin('.', '', await initPlugin(res), _.noop) // '.' is a name that will surely be not found among plugin folders
216 + return new Plugin(SERVER_CODE_ID, '', await initPlugin(res), _.noop) // '.' is a name that will surely be not found among plugin folders
217 }
218 catch (e: any) {
219 return console.error(k + ':', e.message || String(e))
@@ -223,9 +224,8 @@ let serverCodePlugin: void | Plugin
224 serverCode.sub(() => serverCode.compiled().then(x => serverCodePlugin = x))
225 export function mapPlugins<T>(cb:(plugin:Readonly<Plugin>, pluginName:string)=> T, includeServerCode=true) {
226 const entries = Object.entries(plugins)
226 - if (includeServerCode && serverCodePlugin)
227 - entries.push([serverCodePlugin.id, serverCodePlugin])
227 return entries.map(([plName,pl]) => {
228 + if (!includeServerCode && plName === SERVER_CODE_ID) return
229 try { return cb(pl,plName) }
230 catch(e) {
231 console.log('plugin error', plName, String(e))