Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some polyfills #101

Merged
merged 6 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ env:
extends:
- eslint:recommended
- prettier
- plugin:node/recommended
- plugin:n/recommended
- plugin:security/recommended

plugins:
- node
- n
- security

root: true

rules:
node/no-deprecated-api: off
node/no-unsupported-features/es-syntax: off
node/no-unsupported-features/node-builtins: off
node/no-unpublished-require: off
node/no-unpublished-import: off
n/no-deprecated-api: off
n/no-unsupported-features/es-syntax: off
n/no-unsupported-features/node-builtins: off
n/no-unpublished-require: off
n/no-unpublished-import: off
n/no-process-exit: off
# This forces using file extensions in imports, which is a best practice, but refactoring would take some time
n/no-missing-import: off

security/detect-non-literal-fs-filename: off
security/detect-object-injection: off
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ COPY --chown=app:app server server
COPY --chown=app:app --from=builder /app/dist dist

RUN npm ci --production && npm cache clean --force
RUN mkdir -p /app/.config/configstore
RUN ln -s dist/version.json version.json

ENV PORT=1443
Expand Down
2 changes: 1 addition & 1 deletion app/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ parserOptions:
sourceType: module

rules:
node/no-unsupported-features: off
n/no-unsupported-features: off
25 changes: 3 additions & 22 deletions app/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ async function checkCrypto() {
);
return true;
} catch (err) {
try {
window.asmCrypto = await import('asmcrypto.js');
await import('@dannycoates/webcrypto-liner/build/shim');
return true;
} catch (e) {
return false;
}
return false;
}
}

Expand All @@ -66,25 +60,12 @@ function checkStreams() {
}
}

async function polyfillStreams() {
try {
await import('@mattiasbuelens/web-streams-polyfill');
return true;
} catch (e) {
return false;
}
}

export default async function getCapabilities() {
const browser = browserName();
const isMobile = /mobi|android/i.test(navigator.userAgent);
const serviceWorker = 'serviceWorker' in navigator && browser !== 'edge';
let crypto = await checkCrypto();
const nativeStreams = checkStreams();
let polyStreams = false;
if (!nativeStreams) {
polyStreams = await polyfillStreams();
}
let account = typeof AUTH_CONFIG !== 'undefined';
try {
account = account && !!localStorage;
Expand All @@ -106,10 +87,10 @@ export default async function getCapabilities() {
account,
crypto,
serviceWorker,
streamUpload: nativeStreams || polyStreams,
streamUpload: nativeStreams,
streamDownload:
nativeStreams && serviceWorker && browser !== 'safari' && !mobileFirefox,
multifile: nativeStreams || polyStreams,
multifile: nativeStreams,
share,
standalone
};
Expand Down
2 changes: 1 addition & 1 deletion app/ece.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ECETransformer {
name: 'AES-GCM',
length: 128
},
true, // Edge polyfill requires key to be extractable to encrypt :/
false,
['encrypt', 'decrypt']
);
}
Expand Down
1 change: 0 additions & 1 deletion app/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global DEFAULTS LIMITS WEB_UI PREFS */
import 'core-js';
import 'fast-text-encoding'; // MS Edge support
import 'intl-pluralrules';
import choo from 'choo';
import nanotiming from 'nanotiming';
Expand Down
2 changes: 1 addition & 1 deletion app/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Storage {
}

set user(info) {
return this.engine.setItem('user', JSON.stringify(info));
this.engine.setItem('user', JSON.stringify(info));
}

getFileById(id) {
Expand Down
2 changes: 0 additions & 2 deletions app/streams.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* global TransformStream */

export function transformStream(readable, transformer, oncancel) {
try {
return readable.pipeThrough(new TransformStream(transformer));
Expand Down
52 changes: 23 additions & 29 deletions app/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,34 @@ function locale() {
return document.querySelector('html').lang;
}

function loadShim(polyfill) {
return new Promise((resolve, reject) => {
const shim = document.createElement('script');
shim.src = polyfill;
shim.addEventListener('load', () => resolve(true));
shim.addEventListener('error', () => resolve(false));
document.head.appendChild(shim);
});
}

function isFile(id) {
return /^[0-9a-fA-F]{10,16}$/.test(id);
}

function copyToClipboard(str) {
const aux = document.createElement('input');
aux.setAttribute('value', str);
aux.contentEditable = true;
aux.readOnly = true;
document.body.appendChild(aux);
if (navigator.userAgent.match(/iphone|ipad|ipod/i)) {
const range = document.createRange();
range.selectNodeContents(aux);
const sel = getSelection();
sel.removeAllRanges();
sel.addRange(range);
aux.setSelectionRange(0, str.length);
} else {
aux.select();
async function copyToClipboard(str) {
try {
await navigator.clipboard.writeText(str);
} catch {
// Older browsers or the clipboard API fails because of a missing permission
const aux = document.createElement('input');
aux.setAttribute('value', str);
aux.contentEditable = true;
aux.readOnly = true;
document.body.appendChild(aux);
if (navigator.userAgent.match(/iphone|ipad|ipod/i)) {
const range = document.createRange();
range.selectNodeContents(aux);
const sel = getSelection();
sel.removeAllRanges();
sel.addRange(range);
aux.setSelectionRange(0, str.length);
} else {
aux.select();
}
const result = document.execCommand('copy');
document.body.removeChild(aux);
return result;
}
const result = document.execCommand('copy');
document.body.removeChild(aux);
return result;
}

const LOCALIZE_NUMBERS = !!(
Expand Down Expand Up @@ -287,7 +282,6 @@ module.exports = {
copyToClipboard,
arrayToB64,
b64ToArray,
loadShim,
isFile,
openLinksInNewTab,
browserName,
Expand Down
2 changes: 1 addition & 1 deletion common/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const isServer = typeof genmap === 'function';
let prefix = '';
let manifest = {};
try {
//eslint-disable-next-line node/no-missing-require
//eslint-disable-next-line n/no-missing-require
manifest = require('../dist/manifest.json');
} catch (e) {
// use middleware
Expand Down
2 changes: 0 additions & 2 deletions docs/notes/streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
- https://github.com/whatwg/streams/tree/master/reference-implementation
- Examples
- https://github.com/mdn/dom-examples/tree/master/streams
- Polyfill
- https://github.com/MattiasBuelens/web-streams-polyfill

# Encrypted Content Encoding

Expand Down
2 changes: 1 addition & 1 deletion ios/ios.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global window, document, fetch */
/* global window, document */

const MAXFILESIZE = 1024 * 1024 * 1024 * 2;

Expand Down
Loading