Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

Commit

Permalink
Fix issues and add features
Browse files Browse the repository at this point in the history
- Fix Rollup plugin order
- Add view.html
- Add support for folders
  • Loading branch information
qgustavor committed Mar 16, 2017
1 parent f6923c9 commit c208e04
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
6 changes: 4 additions & 2 deletions dist/main.js
Expand Up @@ -9,10 +9,12 @@

var location = window.location
var identifier = (location.hash.length > 2 ? location.hash : location.search || '').substr(1)
var hasFile = identifier.length < 4
var hasFile = identifier.startsWith('!') || identifier.startsWith('F!')

if (navigator.serviceWorker && typeof ReadableStream === 'function') {
navigator.serviceWorker.register('sw.js', {scope: '.'}).then(function () {
navigator.serviceWorker.register('sw.js', {scope: '.'})
.then(navigator.serviceWorker.ready)
.then(function () {
if (hasFile) {
location.reload()
} else {
Expand Down
3 changes: 3 additions & 0 deletions dist/view.html
@@ -0,0 +1,3 @@
<!doctype html><html lang=en><meta charset=utf-8><title>Direct MEGA</title>
<meta name=viewport content="width=device-width,initial-scale=1">
<meta content=yes name=mobile-web-app-capable><style>body{margin:20px;line-height:1.6;font-size:18px;color:#444;padding:0 10px}h1,h2,h3{line-height:1.2}</style><body><noscript>Both MEGA and this page requires JavaScript enabled</noscript><script src="main.js"></script>
14 changes: 7 additions & 7 deletions rollup.fallback.js
@@ -1,25 +1,25 @@
import globals from 'rollup-plugin-node-globals'
import babel from 'rollup-plugin-babel'
import builtins from 'rollup-plugin-node-builtins'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import globals from 'rollup-plugin-node-globals'
import json from 'rollup-plugin-json'
import babel from 'rollup-plugin-babel'
import resolve from 'rollup-plugin-node-resolve'
import uglify from 'rollup-plugin-uglify'

export default {
entry: 'src/fallback.js',
format: 'iife',
plugins: [
json(),
commonjs({
include: 'node_modules/**'
}),
globals(),
builtins(),
resolve({
jsnext: true,
browser: true
}),
json(),
commonjs({
include: 'node_modules/**'
}),
babel({
exclude: 'node_modules/**'
}),
Expand Down
14 changes: 7 additions & 7 deletions rollup.sw.js
@@ -1,25 +1,25 @@
import globals from 'rollup-plugin-node-globals'
import babel from 'rollup-plugin-babel'
import builtins from 'rollup-plugin-node-builtins'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import globals from 'rollup-plugin-node-globals'
import json from 'rollup-plugin-json'
import babel from 'rollup-plugin-babel'
import resolve from 'rollup-plugin-node-resolve'
import uglify from 'rollup-plugin-uglify'

export default {
entry: 'src/sw.js',
format: 'iife',
plugins: [
json(),
commonjs({
include: 'node_modules/**'
}),
globals(),
builtins(),
resolve({
jsnext: true,
browser: true
}),
json(),
commonjs({
include: 'node_modules/**'
}),
babel({
exclude: 'node_modules/**'
}),
Expand Down
4 changes: 4 additions & 0 deletions src/fallback.js
Expand Up @@ -5,6 +5,10 @@ const body = document.body
let url = null

function handleFallback () {
if (location.pathname === '/view') {
showMessage("Viewing files isn't supported in this browser. The file will be downloaded.")
}

const identifier = (location.hash.length > 2 ? location.hash : location.search || '').substr(1)
url = 'https://mega.nz/#' + identifier

Expand Down
4 changes: 2 additions & 2 deletions src/sw.js
Expand Up @@ -30,8 +30,8 @@ function fetchHandler (event) {
const requestURL = event.request.url
const parsedURL = new self.URL(requestURL)
const identifier = (parsedURL.search || '').substr(1)
const requiredFile = identifier.charAt(0) === '!'
? `https://mega.nz/#${identifier}` : null
const hasFile = identifier.startsWith('!') || identifier.startsWith('F!')
const requiredFile = hasFile && `https://mega.nz/#${identifier}`

const promise = requiredFile ? (new Promise((resolve, reject) => {
const file = File.fromURL(requiredFile)
Expand Down

0 comments on commit c208e04

Please sign in to comment.