Skip to content

Commit

Permalink
Merge branch '@fix/bugs'
Browse files Browse the repository at this point in the history
  • Loading branch information
helson-lin committed Dec 21, 2024
2 parents b416244 + a80dde4 commit 54874aa
Show file tree
Hide file tree
Showing 40 changed files with 13,099 additions and 2,600 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module.exports = {
es2021: true,
node: true,
},
extends: 'standard',
extends: [
'eslint:recommended',
],
overrides: [
],
parserOptions: {
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:
# Runs a set of commands using the runners shell
- name: Install Dependencies
run: npm install

- name: Copy SqlLite
run: mkdir -p ./node_modules/sqlite3/lib/binding/ && cp -R package/* ./node_modules/sqlite3/lib/binding/

- name: Build Release
run: npm run pkg
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ lib/*
**/.DS_Store
*.swp
.DS_Store
database/sqlite.db
75 changes: 50 additions & 25 deletions bin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ function createServer (port) {
ws(app).getWss('/')

const { getNetwork, initializeFrontEnd, modifyYml } = Utils

// registerEventCallback
this.registerEventCallback((data) => {
const { name, status } = data
const isSuccess = status === '3'
Utils.msg(
this.config.webhooks,
this.config.webhookType,
'ffandown notification',
`${name}: ${isSuccess ? 'download successful' : `download failed: \n ${data.message}`}`,
)
.then(() => Utils.LOG.warn('message send successfuly'))
.catch(e => {
Utils.LOG.warn('message failed:' + e)
})
})
// websocket
app.ws('/ws', (ws, req) => {
ws.send(Utils.sendWsMsg('connected'))
ws.on('message', async (msg) => {
Expand All @@ -28,15 +45,22 @@ function createServer (port) {
if (key === 'list') {
const list = await this.dbOperation.getAll()
ws.send(Utils.sendWsMsg(list, 'list'))
} else if(key === 'page') {
const { current, pageSize, status } = data
const list = await this.dbOperation.queryByPage({
pageNumber: current, pageSize, status, sortField: 'crt_tm', sortOrder: 'ASC',
})
ws.send(Utils.sendWsMsg(list, 'page'))
}
} catch (e) {
Utils.LOG.error('client:' + e)
}
})
ws.on('close', function (e) {
ws.on('close', function () {
Utils.LOG.info('close connection')
})
})

app.get('/config', async (req, res) => {
res.send({ code: 0, data: this.config })
})
Expand Down Expand Up @@ -83,19 +107,9 @@ function createServer (port) {
for (const urlItem of url) {
// eslint-disable-next-line max-len
this.createDownloadMission({ url: urlItem, dir, preset, enableTimeSuffix: enableTimeSuffix ?? false, useragent, outputformat }).then(() => {
Utils.LOG.info('download success:' + urlItem)
// eslint-disable-next-line max-len
Utils.msg(this.config.webhooks, this.config.webhookType, 'ffandown download success', `${urlItem}`)
.catch(e => {
Utils.LOG.warn('message failed:' + e)
})
Utils.LOG.info('download mission created:' + urlItem)
}).catch((e) => {
Utils.LOG.warn('download failed:' + e)
// eslint-disable-next-line max-len
Utils.msg(this.config.webhooks, this.config.webhookType, 'ffandown download failed', `${urlItem}: ${e}`)
.catch(e => {
Utils.LOG.warn('message failed:' + e)
})
Utils.LOG.warn('download mission create failed:' + e)
})
}
} else {
Expand All @@ -108,18 +122,9 @@ function createServer (port) {
useragent,
outputformat,
}).then(() => {
Utils.LOG.info('download success:' + url)
Utils.msg(this.config.webhooks, this.config.webhookType, 'ffandown download success', `${url}`)
.catch(e => {
Utils.LOG.warn('message failed:' + e)
})
Utils.LOG.info('download mission created:' + url)
}).catch((e) => {
Utils.LOG.warn('download failed:' + e)
// eslint-disable-next-line max-len
Utils.msg(this.config.webhooks, this.config.webhookType, 'ffandown download failed', `${url}: ${e}`)
.catch(e => {
Utils.LOG.warn('message failed:' + e)
})
Utils.LOG.warn('download mission create failed:' + e)
})
}
res.send({ code: 0, message: `${name} video download mission create success` })
Expand Down Expand Up @@ -235,9 +240,29 @@ function createServer (port) {
}
}
})
app.get('/testWebhook', async (req, res) => {
const { webhookType, webhooks } = req.query
try {
Utils.msg(webhooks, webhookType, 'ffandown notification', 'this is a test download notification')
.then(() => {
res.send({ code: 0, message: 'success' })
})
.catch(e => {
res.send({ code: 1, message: e })
})
} catch (e) {
res.send({ code: 1, message: e })
}
})
app.listen(port, async () => {
// initial front end resouce
await initializeFrontEnd()
try {
await initializeFrontEnd()
} catch (e) {
// download frontend static file error;
console.warn(colors.red(e))
process.exit(0)
}
const list = await getNetwork()
const listenString = list.reduce((pre, val) => {
return pre + `\n ${colors.white(' -')} ${colors.brightCyan('http://' + val + ':' + port + '/')}`
Expand Down
Loading

0 comments on commit 54874aa

Please sign in to comment.