mirror of https://github.com/iptv-org/iptv
Delete database/cleanup.js
parent
8ded3338e3
commit
37b77a7d62
@ -1,39 +0,0 @@
|
||||
name: cleanup
|
||||
on:
|
||||
workflow_dispatch:
|
||||
jobs:
|
||||
cleanup:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: echo "::set-output name=branch_name::$(date +'bot/cleanup-%s')"
|
||||
id: create-branch-name
|
||||
- run: |
|
||||
git config user.name 'iptv-bot[bot]'
|
||||
git config user.email '84861620+iptv-bot[bot]@users.noreply.github.com'
|
||||
- run: git checkout -b ${{ steps.create-branch-name.outputs.branch_name }}
|
||||
- run: npm install
|
||||
- run: node scripts/commands/create-database.js
|
||||
- run: node scripts/commands/cleanup-database.js
|
||||
- run: node scripts/commands/update-playlists.js
|
||||
- run: |
|
||||
git add channels/*
|
||||
git commit -m "[Bot] Update playlists"
|
||||
- uses: tibdex/github-app-token@v1
|
||||
if: ${{ !env.ACT }}
|
||||
id: create-app-token
|
||||
with:
|
||||
app_id: ${{ secrets.APP_ID }}
|
||||
private_key: ${{ secrets.APP_PRIVATE_KEY }}
|
||||
- uses: repo-sync/pull-request@v2
|
||||
if: ${{ github.ref == 'refs/heads/master' }}
|
||||
id: pull-request
|
||||
with:
|
||||
github_token: ${{ steps.create-app-token.outputs.token }}
|
||||
source_branch: ${{ steps.create-branch-name.outputs.branch_name }}
|
||||
destination_branch: 'master'
|
||||
pr_title: '[Bot] Remove broken links'
|
||||
pr_body: |
|
||||
This pull request is created by [cleanup][1] workflow.
|
||||
|
||||
[1]: https://github.com/iptv-org/iptv/actions/runs/${{ github.run_id }}
|
@ -1,25 +0,0 @@
|
||||
const { db, logger } = require('../../core')
|
||||
const _ = require('lodash')
|
||||
|
||||
async function main() {
|
||||
logger.info(`loading streams...`)
|
||||
await db.streams.load()
|
||||
let streams = await db.streams.find({})
|
||||
|
||||
logger.info(`removing broken links...`)
|
||||
let removed = 0
|
||||
const failed = _.filter(streams, { status: 'error' })
|
||||
for (const stream of failed) {
|
||||
const hasDuplicate = _.find(streams, s => s.channel === stream.channel && s.status !== 'error')
|
||||
if (hasDuplicate) {
|
||||
await db.streams.remove({ _id: stream._id })
|
||||
removed++
|
||||
}
|
||||
}
|
||||
|
||||
db.streams.compact()
|
||||
|
||||
logger.info(`removed ${removed} links`)
|
||||
}
|
||||
|
||||
main()
|
@ -1,34 +0,0 @@
|
||||
const { execSync } = require('child_process')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copyFileSync(
|
||||
'tests/__data__/input/database/db_cleanup.streams.db',
|
||||
'tests/__data__/output/streams.db'
|
||||
)
|
||||
|
||||
const stdout = execSync('DB_DIR=tests/__data__/output npm run db:cleanup', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
})
|
||||
|
||||
it('can remove broken links from database', () => {
|
||||
expect(content('tests/__data__/output/streams.db')).toEqual(
|
||||
content('tests/__data__/expected/database/db_cleanup.streams.db')
|
||||
)
|
||||
})
|
||||
|
||||
function content(filepath) {
|
||||
const data = fs.readFileSync(path.resolve(filepath), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
|
||||
return data
|
||||
.split('\n')
|
||||
.filter(l => l)
|
||||
.map(l => {
|
||||
return JSON.parse(l)
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue