Skip to content

Commit

Permalink
Apply new linting rules (#568)
Browse files Browse the repository at this point in the history
* Add prettier config

* Prettify repo

* Update upload.js
  • Loading branch information
kvz authored Mar 26, 2023
1 parent b61939c commit 1db985a
Show file tree
Hide file tree
Showing 72 changed files with 1,863 additions and 1,705 deletions.
17 changes: 10 additions & 7 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"presets": [
[ "@babel/preset-env", {
"modules": false,
"corejs": false,
"forceAllTransforms": true
} ]
]
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"corejs": false,
"forceAllTransforms": true
}
]
]
}
13 changes: 7 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"extends": [
"transloadit"
],
"extends": ["transloadit", "prettier"],
"env": {
"es6": true,
"node": false,
Expand All @@ -21,9 +19,12 @@
"class-methods-use-this": ["off"],
"no-use-before-define": ["off"],
"no-param-reassign": ["off"],
"import/no-extraneous-dependencies": ["error", {
"devDependencies": ["test/**/*.js"]
}],
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": ["test/**/*.js"]
}
],
"import/extensions": ["error", "ignorePackages"]
},
"overrides": [
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Report a bug or incorrect behavior
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Execute command '...'
2. Start upload '...'
3. See error
Expand All @@ -23,6 +23,7 @@ A clear and concise description of what you expected to happen.

**Setup details**
Please provide following details, if applicable to your situation:

- Runtime environment: [e.g. Browser, Node.js, React Native]
- Used tus-js-client version: [can be obtained by running `npm ls`]
- Used tus server software: [e.g. tusd, tus-node-server etc]
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea or improvement
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Ask a general question about using tus-js-client
title: ''
labels: question
assignees: ''

---

**Question**
Please place your question here.

**Setup details**
Please provide following details, if applicable to your situation:

- Runtime environment: [e.g. Browser, Node.js, React Native]
- Used tus-js-client version: [can be obtained by running `npm ls`]
- Used tus server software: [e.g. tusd, tus-node-server etc]
29 changes: 14 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ jobs:
fail-fast: false
matrix:
include:
- desc: "Browserstack"
suite: "browserstack"
- desc: "Puppeteer"
suite: "puppeteer"
- desc: "Types"
suite: "types"
- desc: "Node.js 14"
suite: "node"
- desc: 'Browserstack'
suite: 'browserstack'
- desc: 'Puppeteer'
suite: 'puppeteer'
- desc: 'Types'
suite: 'types'
- desc: 'Node.js 14'
suite: 'node'
node: 14
- desc: "Node.js 16"
suite: "node"
- desc: 'Node.js 16'
suite: 'node'
node: 16
- desc: "Node.js 18"
suite: "node"
- desc: 'Node.js 18'
suite: 'node'
node: 18
name: ${{ matrix.desc }}
steps :
steps:
- name: Check out sources
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -59,7 +59,6 @@ jobs:
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_KEY: ${{ secrets.BROWSERSTACK_KEY }}

# @TODO: port this Travis CI automation to GHA one day:
# deploy:
# provider: npm
Expand All @@ -70,4 +69,4 @@ jobs:
# on:
# tags: true
# repo: tus/tus-js-client
# node_js: 12
# node_js: 12
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
lib.es5/
lib.esm/
node_modules/
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"printWidth": 100,
"semi": false,
"singleQuote": true,
"useTabs": false,
"jsxSingleQuote": false
}
80 changes: 40 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img alt="Tus logo" src="https://github.com/tus/tus.io/blob/main/assets/img/tus1.png?raw=true" width="30%" align="right" />

> **tus** is a protocol based on HTTP for *resumable file uploads*. Resumable
> **tus** is a protocol based on HTTP for _resumable file uploads_. Resumable
> means that an upload can be interrupted at any moment and can be resumed without
> re-uploading the previous data again. An interruption may happen willingly, if
> the user wants to pause, or by accident in case of an network issue or server
Expand All @@ -18,50 +18,50 @@ This branch contains tus-js-client v3. If you are looking for the previous major
## Example

```js
input.addEventListener("change", function(e) {
// Get the selected file from the input element
var file = e.target.files[0]

// Create a new tus upload
var upload = new tus.Upload(file, {
endpoint: "http://localhost:1080/files/",
retryDelays: [0, 3000, 5000, 10000, 20000],
metadata: {
filename: file.name,
filetype: file.type
},
onError: function(error) {
console.log("Failed because: " + error)
},
onProgress: function(bytesUploaded, bytesTotal) {
var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
console.log(bytesUploaded, bytesTotal, percentage + "%")
},
onSuccess: function() {
console.log("Download %s from %s", upload.file.name, upload.url)
}
})

// Check if there are any previous uploads to continue.
upload.findPreviousUploads().then(function (previousUploads) {
// Found previous uploads so we select the first one.
if (previousUploads.length) {
upload.resumeFromPreviousUpload(previousUploads[0])
}

// Start the upload
upload.start()
})
input.addEventListener('change', function (e) {
// Get the selected file from the input element
var file = e.target.files[0]

// Create a new tus upload
var upload = new tus.Upload(file, {
endpoint: 'http://localhost:1080/files/',
retryDelays: [0, 3000, 5000, 10000, 20000],
metadata: {
filename: file.name,
filetype: file.type,
},
onError: function (error) {
console.log('Failed because: ' + error)
},
onProgress: function (bytesUploaded, bytesTotal) {
var percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2)
console.log(bytesUploaded, bytesTotal, percentage + '%')
},
onSuccess: function () {
console.log('Download %s from %s', upload.file.name, upload.url)
},
})

// Check if there are any previous uploads to continue.
upload.findPreviousUploads().then(function (previousUploads) {
// Found previous uploads so we select the first one.
if (previousUploads.length) {
upload.resumeFromPreviousUpload(previousUploads[0])
}

// Start the upload
upload.start()
})
})
```

## Documentation

* [Installation & Requirements](/docs/installation.md)
* [Usage & Examples](/docs/usage.md)
* [API Reference](/docs/api.md)
* [Contribution Guidelines](/docs/contributing.md)
* [FAQ & Common issues](/docs/faq.md)
- [Installation & Requirements](/docs/installation.md)
- [Usage & Examples](/docs/usage.md)
- [API Reference](/docs/api.md)
- [Contribution Guidelines](/docs/contributing.md)
- [FAQ & Common issues](/docs/faq.md)

## Build status

Expand Down
6 changes: 3 additions & 3 deletions demos/browser/demo.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
body {
padding-top: 40px;
padding-top: 40px;
}

.progress {
height: 32px;
height: 32px;
}

a.btn {
margin-bottom: 2px;
margin-bottom: 2px;
}
39 changes: 20 additions & 19 deletions demos/browser/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@

'use strict'

let upload = null
let upload = null
let uploadIsRunning = false
const toggleBtn = document.querySelector('#toggle-btn')
const input = document.querySelector('input[type=file]')
const progress = document.querySelector('.progress')
const progressBar = progress.querySelector('.bar')
const alertBox = document.querySelector('#support-alert')
const uploadList = document.querySelector('#upload-list')
const chunkInput = document.querySelector('#chunksize')
const parallelInput = document.querySelector('#paralleluploads')
const endpointInput = document.querySelector('#endpoint')

function reset () {
const toggleBtn = document.querySelector('#toggle-btn')
const input = document.querySelector('input[type=file]')
const progress = document.querySelector('.progress')
const progressBar = progress.querySelector('.bar')
const alertBox = document.querySelector('#support-alert')
const uploadList = document.querySelector('#upload-list')
const chunkInput = document.querySelector('#chunksize')
const parallelInput = document.querySelector('#paralleluploads')
const endpointInput = document.querySelector('#endpoint')

function reset() {
input.value = ''
toggleBtn.textContent = 'start upload'
upload = null
uploadIsRunning = false
}

function askToResumeUpload (previousUploads, currentUpload) {
function askToResumeUpload(previousUploads, currentUpload) {
if (previousUploads.length === 0) return

let text = 'You tried to upload this file previously at these times:\n\n'
previousUploads.forEach((previousUpload, index) => {
text += `[${index}] ${previousUpload.creationTime}\n`
})
text += '\nEnter the corresponding number to resume an upload or press Cancel to start a new upload'
text +=
'\nEnter the corresponding number to resume an upload or press Cancel to start a new upload'

const answer = prompt(text)
const index = parseInt(answer, 10)
Expand All @@ -39,7 +40,7 @@ function askToResumeUpload (previousUploads, currentUpload) {
}
}

function startUpload () {
function startUpload() {
const file = input.files[0]
// Only continue if a file has actually been selected.
// IE will trigger a change event even if we reset the input element
Expand All @@ -66,11 +67,11 @@ function startUpload () {
chunkSize,
retryDelays: [0, 1000, 3000, 5000],
parallelUploads,
metadata : {
metadata: {
filename: file.name,
filetype: file.type,
},
onError (error) {
onError(error) {
if (error.originalRequest) {
if (window.confirm(`Failed because: ${error}\nDo you want to retry?`)) {
upload.start()
Expand All @@ -83,12 +84,12 @@ function startUpload () {

reset()
},
onProgress (bytesUploaded, bytesTotal) {
onProgress(bytesUploaded, bytesTotal) {
const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2)
progressBar.style.width = `${percentage}%`
console.log(bytesUploaded, bytesTotal, `${percentage}%`)
},
onSuccess () {
onSuccess() {
const anchor = document.createElement('a')
anchor.textContent = `Download ${upload.file.name} (${upload.file.size} bytes)`
anchor.href = upload.url
Expand Down
Loading

0 comments on commit 1db985a

Please sign in to comment.