Skip to content

Commit

Permalink
Allows to add multiple urls (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
6c65726f79 committed Mar 12, 2023
1 parent 8a13aa3 commit a2d2406
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
31 changes: 22 additions & 9 deletions src/services/FileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
modalController
} from '@ionic/vue';
import router from '../router';
import parseTorrent from 'parse-torrent'
import parseTorrent, { remote } from 'parse-torrent'
import AddTorrent from '../views/AddTorrent.vue'
import { Utils } from './Utils';
import { Emitter } from "./Emitter";
Expand Down Expand Up @@ -180,14 +180,19 @@ export const FileHandler = {
}
if(magnets.length>0) this.newTorrentModal(magnets,"magnet");
},
readURL(url: string): void {
if(this.isValidUrl(url)){
parseTorrent.remote(url, (err, parsedTorrent) => {
const data = err ? {} : parsedTorrent;
if(data) {
this.newTorrentModal([{data,torrent:url}],"url");
}
})
async readURL(text: string): Promise<void> {
const list = [];
const match = text.match(/\S+/g) || [];

for(const url of match){
if(this.isValidUrl(url)){
const data = await parseRemoteTorrent(url);
list.push({data, torrent:url});
}
}

if(list.length>0){
this.newTorrentModal(list,"url");
}
},
isValidUrl(str: string): boolean {
Expand Down Expand Up @@ -245,3 +250,11 @@ export const FileHandler = {
return result;
}
}

const parseRemoteTorrent = (url: string) => {
return new Promise((resolve) => {
remote(url, (err, parsedTorrent) => {
resolve(err ? {} : parsedTorrent);
})
})
}
6 changes: 3 additions & 3 deletions src/views/AddTorrent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
</ion-label>
</ion-item>

<ion-item v-if="type=='url'">
<ion-item v-if="type=='url' && !multiple">
<ion-label class="label no-wrap">
<div>URL</div>
<span class="selectable">{{files[0].torrent}}</span>
Expand Down Expand Up @@ -187,9 +187,9 @@
v-on:ionChange="checboxUpdate($event,item.data.infoHash)">
</ion-checkbox>
</div>
<div class="middle" @click="fileTitle(item.data.name)" @contextmenu="fileTitle(item.data.name, $event)">
<div class="middle" @click="fileTitle(item.data.name || item.torrent)" @contextmenu="fileTitle(item.data.name || item.torrent, $event)">
<div class="name">
{{item.data.name}}
{{item.data.name || item.torrent}}
</div>
<div class="details">
<ion-icon color="medium" :ios="documentOutline" :md="documentSharp"></ion-icon>
Expand Down
9 changes: 8 additions & 1 deletion src/views/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ import { defineComponent, inject } from 'vue';
import {
isPlatform,
modalController,
loadingController,
popoverController,
actionSheetController,
alertController,
Expand Down Expand Up @@ -739,6 +740,7 @@ export default defineComponent({
inputs: [
{
name: 'url',
type: 'textarea',
placeholder: Locale.torrentFileLink
}
],
Expand All @@ -750,7 +752,12 @@ export default defineComponent({
{
text: Locale.ok,
handler: (data: Record<string,any>) => {
FileHandler.readURL(data.url);
loadingController.create({}).then(loading => {
loading.present();
FileHandler.readURL(data.url).then(() => {
loading.dismiss();
})
});
},
},
],
Expand Down

0 comments on commit a2d2406

Please sign in to comment.