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
9b79fd6e
Commit
9b79fd6e
authored
Oct 07, 2020
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Application Page: Can create from WebTorrent Zip
parent
c7209288
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
2 deletions
+104
-2
gadget/gadget_cribjs_page_add_application.html
gadget/gadget_cribjs_page_add_application.html
+3
-0
gadget/gadget_cribjs_page_add_application.js
gadget/gadget_cribjs_page_add_application.js
+31
-0
gadget/gadget_landing_cribjs.html
gadget/gadget_landing_cribjs.html
+1
-0
gadget/gadget_landing_cribjs.js
gadget/gadget_landing_cribjs.js
+69
-2
No files found.
gadget/gadget_cribjs_page_add_application.html
View file @
9b79fd6e
...
...
@@ -41,6 +41,9 @@
<div
class=
"form-group"
>
<label>
Zip File:
<input
name=
"load-zip-file"
class=
"load-zip-file form-control"
type=
"file"
size=
"30"
></label>
<label>
Or WebTorrent Magnet:
<input
name=
"load-zip-magnet"
class=
"load-zip-magnet form-control"
type=
"text"
size=
"60"
value=
""
></label>
<label>
Or Zip Url:
<input
name=
"load-zip-url"
class=
"load-zip-url form-control"
type=
"text"
size=
"60"
value=
"apps/hello-world-template.zip"
></label>
...
...
gadget/gadget_cribjs_page_add_application.js
View file @
9b79fd6e
...
...
@@ -145,6 +145,10 @@
.
querySelector
(
"
form.crib-load-from-zip .load-zip-file
"
).
files
.
length
!==
0
)
{
logAddApp
(
gadget
,
"
Will load Zip from File
"
);
promise_list
.
push
(
loadCribJSFromZipFile
(
gadget
,
event
,
logAddApp
));
}
else
if
(
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip .load-zip-magnet
"
).
value
)
{
logAddApp
(
gadget
,
"
Will load Zip from Magnet
"
);
promise_list
.
push
(
loadCribJSFromMagnet
(
gadget
,
event
,
logAddApp
));
}
else
if
(
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip .load-zip-url
"
).
value
)
{
logAddApp
(
gadget
,
"
Will load Zip from Url
"
);
...
...
@@ -213,6 +217,28 @@
});
}
function
loadCribJSFromMagnet
(
gadget
,
event
,
logFunction
)
{
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
getDeclaredGadget
(
"
jio_cribjs
"
);
})
.
push
(
function
(
jio_cribjs_gadget
)
{
return
jio_cribjs_gadget
.
loadFromMagnet
({
path
:
document
.
location
.
href
,
zip_magnet
:
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip .load-zip-magnet
"
).
value
,
from_path
:
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip .load-from-zip-path
"
).
value
,
to_path
:
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip .load-zip-to-path
"
).
value
,
application_id
:
"
cribjs
"
},
function
(
str
)
{
logFunction
(
gadget
,
str
);
});
});
}
function
loadCribJSFromZipUrl
(
gadget
,
event
,
logFunction
)
{
return
RSVP
.
Queue
()
.
push
(
function
()
{
...
...
@@ -309,6 +335,11 @@
.
querySelector
(
"
form.crib-load-from-zip .load-zip-url
"
)
.
value
=
options
.
zip_app_url
;
}
if
(
options
.
hasOwnProperty
(
"
magnet_link
"
))
{
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip .load-zip-magnet
"
)
.
value
=
options
.
magnet_link
;
}
if
(
options
.
hasOwnProperty
(
"
redirect_url
"
))
{
gadget
.
props
.
element
.
querySelector
(
"
form.crib-load-from-zip .redirect-url
"
)
...
...
gadget/gadget_landing_cribjs.html
View file @
9b79fd6e
...
...
@@ -10,6 +10,7 @@
<script
src=
"../lib/renderjs.js"
></script>
<script
src=
"../lib/jszip.js"
type=
"text/javascript"
></script>
<script
src=
"../lib/mimetype.js"
type=
"text/javascript"
></script>
<script
src=
"../lib/webtorrent.min.js"
type=
"text/javascript"
></script>
<script
src=
"./gadget_landing_cribjs.js"
></script>
</head>
<body>
...
...
gadget/gadget_landing_cribjs.js
View file @
9b79fd6e
/*jslint browser: true, indent: 2, maxlen: 80*/
/*globals RSVP, rJS,
location, console, fetch, Promise*/
(
function
(
window
,
document
,
RSVP
,
rJS
,
location
,
console
,
JSZip
,
mimeType
)
{
(
function
(
window
,
document
,
RSVP
,
rJS
,
location
,
console
,
JSZip
,
mimeType
,
WebTorrent
)
{
"
use strict
"
;
function
loadZipIntoCrib
(
gadget
,
zip
,
from_path
,
path_to_load
,
logFunction
)
{
...
...
@@ -61,6 +62,44 @@
return
RSVP
.
all
(
promise_list
);
}
function
downloadTorrent
(
gadget
,
torrentId
,
logFunction
)
{
logFunction
(
"
Preparing
"
);
return
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
var
client
=
new
WebTorrent
();
client
.
on
(
'
error
'
,
function
(
err
)
{
reject
(
err
.
message
);
});
client
.
add
(
torrentId
,
function
(
torrent
)
{
logFunction
(
'
Got torrent metadata!
'
);
logFunction
(
'
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
()
{
logFunction
(
'
Progress:
'
+
(
torrent
.
progress
*
100
).
toFixed
(
1
)
+
'
%
'
);
},
5000
);
torrent
.
files
[
0
].
getBlob
(
function
(
error
,
result
)
{
if
(
error
)
{
reject
(
error
);
}
resolve
(
result
);
});
torrent
.
on
(
'
done
'
,
function
()
{
logFunction
(
"
Torrent Loaded 100%
"
);
clearInterval
(
interval
);
});
});
});
}
function
loadContentFromZIPFile
(
gadget
,
options
,
logFunction
)
{
if
(
logFunction
===
undefined
)
{
logFunction
=
console
.
log
;
...
...
@@ -123,6 +162,30 @@
});
}
function
loadContentFromMagnet
(
gadget
,
options
,
logFunction
)
{
if
(
logFunction
===
undefined
)
{
logFunction
=
console
.
log
;
}
var
path_to_load
=
options
.
to_path
,
file_list
,
from_path
=
options
.
from_path
,
magnet_uri
=
options
.
zip_magnet
,
jio_gadget
,
url_list
=
[],
url_number
=
0
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
logFunction
(
"
Fetching Torrent
"
);
return
downloadTorrent
(
gadget
,
magnet_uri
,
logFunction
);
})
.
push
(
JSZip
.
loadAsync
)
.
push
(
function
(
zip
)
{
return
loadZipIntoCrib
(
gadget
,
zip
,
from_path
,
path_to_load
,
logFunction
);
})
.
push
(
function
()
{
logFunction
(
"
Imported Zip Successfully
"
);
},
function
(
e
)
{
logFunction
(
e
);
throw
e
;
});
}
rJS
(
window
)
.
ready
(
function
(
g
)
{
g
.
props
=
{};
...
...
@@ -133,10 +196,14 @@
.
declareMethod
(
'
loadFromZipFile
'
,
function
(
options
,
logFunction
)
{
return
loadContentFromZIPFile
(
this
,
options
,
logFunction
);
})
.
declareMethod
(
'
loadFromMagnet
'
,
function
(
options
,
logFunction
)
{
return
loadContentFromMagnet
(
this
,
options
,
logFunction
);
})
.
declareAcquiredMethod
(
"
crib_sw_put
"
,
"
crib_sw_put
"
)
.
declareAcquiredMethod
(
"
getSetting
"
,
"
getSetting
"
)
.
allowPublicAcquisition
(
"
getSetting
"
,
function
(
argument_list
)
{
return
this
.
getSetting
(
argument_list
[
0
],
argument_list
[
1
]);
});
}(
window
,
document
,
RSVP
,
rJS
,
location
,
console
,
JSZip
,
mimeType
));
\ No newline at end of file
}(
window
,
document
,
RSVP
,
rJS
,
location
,
console
,
JSZip
,
mimeType
,
WebTorrent
));
\ No newline at end of file
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