From 36e0b140cdd076ab3f5488035a4dafde32774150 Mon Sep 17 00:00:00 2001 From: haiyangcui Date: Sun, 4 Oct 2020 12:20:24 +0200 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=AD=E6=96=87=E4=B9=B1?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/IPTV.vue | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/components/IPTV.vue b/src/components/IPTV.vue index 5a478ea..79ed0f7 100644 --- a/src/components/IPTV.vue +++ b/src/components/IPTV.vue @@ -182,27 +182,29 @@ export default { importSites () { const options = { filters: [ - { name: 'JSON file', extensions: ['json'] }, - { name: 'm3u file', extensions: ['m3u'] } + { name: 'm3u file', extensions: ['m3u'] }, + { name: 'JSON file', extensions: ['json'] } ], properties: ['openFile'] } remote.dialog.showOpenDialog(options).then(result => { if (!result.canceled) { - iptv.clear() result.filePaths.forEach(file => { if (file.endsWith('json')) { var str = fs.readFileSync(file) const json = JSON.parse(str) - iptv.bulkAdd(json).then(e => { - this.getAllSites() + iptv.clear().then(res => { + iptv.bulkAdd(json).then(e => { + this.getAllSites() + this.$message.success('导入成功') + }) }) - this.$message.success('导入成功') } else if (file.endsWith('m3u')) { var m3u8 = require('m3u8') var parser = m3u8.createStream() - var m3ufile = fs.createReadStream(file) + var m3ufile = fs.createReadStream(file, { encoding: 'utf-8' }) m3ufile.pipe(parser) + var docs = [] parser.on('item', function (item) { var prop = item.properties if (prop.title && prop.uri && prop.uri.endsWith('m3u8')) { @@ -210,9 +212,15 @@ export default { name: prop.title, url: prop.uri } - iptv.add(doc) + docs.push(doc) } }) + iptv.clear().then(res => { + iptv.bulkAdd(docs).then(e => { + this.getAllSites() + this.$message.success('导入成功') + }) + }) } }) }