mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
add v23 support to instance app
This commit is contained in:
parent
966d7aa734
commit
ba979aab93
1
packages/pockethost/src/instance-app/.gitignore
vendored
Normal file
1
packages/pockethost/src/instance-app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
pb_data
|
@ -0,0 +1,39 @@
|
||||
onBootstrap((e) => {
|
||||
e.next()
|
||||
const { mkLog } = /** @type {Lib} */ (require(`${__hooks}/_ph_lib.js`))
|
||||
|
||||
const log = mkLog(`admin-sync`)
|
||||
|
||||
const { id, email, tokenKey, passwordHash } = (() => {
|
||||
try {
|
||||
return /** @type{{id:string, email:string, tokenKey:string,passwordHash:string}} */ (
|
||||
JSON.parse(process.env.ADMIN_SYNC)
|
||||
)
|
||||
} catch (e) {
|
||||
return { id: '', email: '', tokenKey: '', passwordHash: '' }
|
||||
}
|
||||
})()
|
||||
|
||||
if (!email) {
|
||||
log(`Not active - skipped`)
|
||||
return
|
||||
}
|
||||
|
||||
const update = () =>
|
||||
e.app
|
||||
.db()
|
||||
.newQuery(
|
||||
`
|
||||
insert or replace into _superusers (id, email, tokenKey, password) values ({:id}, {:email}, {:tokenKey}, {:passwordHash})
|
||||
`,
|
||||
)
|
||||
.bind({ id, email, tokenKey, passwordHash })
|
||||
.execute()
|
||||
|
||||
try {
|
||||
update()
|
||||
log(`Success updating admin credentials ${email}`)
|
||||
} catch (e) {
|
||||
log(`Failed to update admin credentials ${email}: ${e}`)
|
||||
}
|
||||
})
|
19
packages/pockethost/src/instance-app/v23/pb_hooks/_ph_lib.js
Normal file
19
packages/pockethost/src/instance-app/v23/pb_hooks/_ph_lib.js
Normal file
@ -0,0 +1,19 @@
|
||||
/** @type {Lib['mkLog']} */
|
||||
const mkLog =
|
||||
(namespace) =>
|
||||
/**
|
||||
* @param {...any} s
|
||||
* @returns
|
||||
*/
|
||||
(...s) =>
|
||||
console.log(
|
||||
`[${namespace}]`,
|
||||
...s.map((p) => {
|
||||
if (typeof p === 'object') return JSON.stringify(p, null, 2)
|
||||
return p
|
||||
}),
|
||||
)
|
||||
|
||||
module.exports = {
|
||||
mkLog,
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
migrate(
|
||||
(app) => {
|
||||
try {
|
||||
const APP_DEFAULTS = {
|
||||
appName: 'Acme',
|
||||
appURL: 'http://localhost:8090',
|
||||
senderName: 'Support',
|
||||
senderAddress: 'support@example.com',
|
||||
}
|
||||
|
||||
const { PH_APP_NAME, PH_INSTANCE_URL } = process.env
|
||||
|
||||
const settings = app.settings()
|
||||
|
||||
const fix = (field, newValue) => {
|
||||
if (!newValue || settings.meta[field] !== APP_DEFAULTS[field]) return
|
||||
settings.meta[field] = newValue
|
||||
}
|
||||
fix(`appName`, PH_APP_NAME)
|
||||
fix(`appUrl`, PH_INSTANCE_URL)
|
||||
fix(`senderName`, PH_APP_NAME)
|
||||
fix(`senderAddress`, `${PH_APP_NAME}@app.pockethost.io`)
|
||||
|
||||
app.save(settings)
|
||||
|
||||
console.log(`***defaults successfully applied`)
|
||||
} catch (e) {
|
||||
console.error(`***error applying defaults: ${e}`)
|
||||
}
|
||||
},
|
||||
(db) => {
|
||||
// add down queries...
|
||||
},
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user