Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cribjs-editor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
cribjs-editor
Commits
55b64dfe
Commit
55b64dfe
authored
Jul 15, 2020
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add import torrent from magnet
parent
b57bd50a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
8 deletions
+82
-8
gadget/gadget_cribjs_page_save_load.html
gadget/gadget_cribjs_page_save_load.html
+10
-0
gadget/gadget_cribjs_page_save_load.js
gadget/gadget_cribjs_page_save_load.js
+72
-8
No files found.
gadget/gadget_cribjs_page_save_load.html
View file @
55b64dfe
...
...
@@ -59,6 +59,16 @@
</label>
<textarea
name=
"load-zip-path"
class=
"magnet-link form-control"
readonly
value=
"cribeditor/v1.1"
>
Data
</textarea>
</div>
<form
class=
"crib-import-torrent form-inline"
>
<h3>
Import from zip Torrent
</h3>
<div
class=
"log"
style=
"display:none;"
>
</div>
<div
class=
"form-group"
>
<label>
Magnet:
<input
name=
"zip-magnet"
class=
"zip-magnet form-control"
type=
"text"
size=
"40"
></label>
</div>
<button
name=
"load-zip-magnet"
class=
"load-zip-magnet btn btn-default"
type=
"submit"
>
Import from Torrent
</button>
</form>
</div>
<div
data-gadget-url=
"./gadget_jio.html"
data-gadget-scope=
"jio_gadget"
...
...
gadget/gadget_cribjs_page_save_load.js
View file @
55b64dfe
/*global window, rJS, loopEventListener, RSVP, console, document, saveAs, WebTorrent,
File*/
File
, setInterval, clearInterval
*/
/*jslint nomen: true, indent: 2, maxerr: 3*/
(
function
(
window
,
rJS
,
loopEventListener
,
JSZip
,
FileSaver
,
WebTorrent
)
{
"
use strict
"
;
...
...
@@ -12,6 +12,46 @@
return
"
.
"
+
extension
;
}
function
log
(
gadget
,
str
)
{
var
p
=
document
.
createElement
(
'
p
'
),
old_p_element
=
gadget
.
props
.
element
.
querySelector
(
'
.log p
'
),
log_element
=
gadget
.
props
.
element
.
querySelector
(
'
.log
'
);
if
(
old_p_element
)
{
old_p_element
.
remove
();
}
p
.
innerHTML
=
str
;
log_element
.
style
.
display
=
""
;
log_element
.
appendChild
(
p
);
}
function
downloadTorrent
(
gadget
,
torrentId
)
{
return
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
var
client
=
new
WebTorrent
();
client
.
on
(
'
error
'
,
function
(
err
)
{
reject
(
err
.
message
);
});
client
.
add
(
torrentId
,
function
(
torrent
)
{
log
(
gadget
,
'
Got torrent metadata!
'
);
log
(
gadget
,
'
Torrent info hash:
'
+
torrent
.
infoHash
+
'
'
+
'
<a href="
'
+
torrent
.
magnetURI
+
'
" target="_blank">[Magnet URI]</a>
'
+
'
<a href="
'
+
torrent
.
torrentFileBlobURL
+
'
" target="_blank" download="
'
+
torrent
.
name
+
'
.torrent">[Download .torrent]</a>
'
);
// Torrents can contain many files. Here we suppose there is only one zip
var
interval
=
setInterval
(
function
()
{
log
(
gadget
,
'
Progress:
'
+
(
torrent
.
progress
*
100
).
toFixed
(
1
)
+
'
%
'
);
},
5000
);
torrent
.
on
(
'
done
'
,
function
()
{
log
(
gadget
,
"
Done
"
);
resolve
(
torrent
.
files
);
clearInterval
(
interval
);
});
});
});
}
// Zip Methods
function
prepareZip
(
gadget
,
event
,
options
)
{
var
path_to_save
,
path_to_save_length
,
crib_sw_gadget
,
...
...
@@ -110,21 +150,39 @@
.
push
(
console
.
log
,
console
.
log
);
}
function
loadContentFromZIP
(
gadget
,
event
)
{
var
path_to_load
,
path_to_load_length
,
file_list
,
crib_sw_gadget
,
jio_gadget
,
url_list
=
[],
file
,
url_number
=
0
;
path_to_load
=
gadget
.
props
.
element
.
querySelector
(
'
form.crib-load-from-zip .load-zip-path
'
).
value
;
function
loadContentFromZIPFile
(
gadget
,
event
)
{
var
file_list
,
file
;
file_list
=
gadget
.
props
.
element
.
querySelector
(
'
form.crib-load-from-zip .load-zip-file
'
).
files
;
if
(
file_list
.
length
===
0
)
{
gadget
.
props
.
element
.
querySelector
(
"
.crib-load-from-zip-status
"
)
.
textContent
=
"
Please put a Zip at
"
+
Date
();
return
;
}
path_to_load_length
=
path_to_load
.
length
;
file
=
file_list
[
0
];
return
loadContentFromZIP
(
gadget
,
event
,
file
);
}
function
loadContentFromZIPMagnet
(
gadget
,
event
)
{
var
magnet
;
magnet
=
gadget
.
props
.
element
.
querySelector
(
'
form.crib-import-torrent .zip-magnet
'
).
value
;
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
downloadTorrent
(
gadget
,
magnet
);
})
.
push
(
function
(
files
)
{
return
loadContentFromZIP
(
gadget
,
event
,
files
[
0
]);
});
}
function
loadContentFromZIP
(
gadget
,
event
,
zip_data
)
{
var
path_to_load
,
path_to_load_length
,
file_list
,
crib_sw_gadget
,
jio_gadget
,
url_list
=
[],
file
,
url_number
=
0
;
path_to_load
=
gadget
.
props
.
element
.
querySelector
(
'
form.crib-load-from-zip .load-zip-path
'
).
value
;
path_to_load_length
=
path_to_load
.
length
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
JSZip
.
loadAsync
(
file
);
return
JSZip
.
loadAsync
(
zip_data
);
})
.
push
(
function
(
zip
)
{
var
promise_list
=
[];
...
...
@@ -212,7 +270,7 @@
gadget
.
props
.
element
.
querySelector
(
"
.crib-load-from-zip
"
),
'
submit
'
,
false
,
function
(
event
)
{
loadContentFromZIP
(
gadget
,
event
);
}
function
(
event
)
{
loadContentFromZIP
File
(
gadget
,
event
);
}
));
promise_list
.
push
(
loopEventListener
(
gadget
.
props
.
element
.
querySelector
(
"
.crib-export-torrent
"
),
...
...
@@ -220,6 +278,12 @@
false
,
function
(
event
)
{
seedZip
(
gadget
,
event
);
}
));
promise_list
.
push
(
loopEventListener
(
gadget
.
props
.
element
.
querySelector
(
"
.crib-import-torrent
"
),
'
submit
'
,
false
,
function
(
event
)
{
loadContentFromZIPMagnet
(
gadget
,
event
);
}
));
return
RSVP
.
all
(
promise_list
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment