Last active
January 26, 2022 23:46
-
-
Save H7-25/ec37ab80d7cfa8168bad6172e019c498 to your computer and use it in GitHub Desktop.
instantiate-uppy with puppy audio and translations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Uppy from '@uppy/core' | |
import Dashboard from '@uppy/dashboard' | |
import Tus from '@uppy/tus' | |
import Webcam from '@uppy/webcam' | |
import Audio from '@zadkiel/uppy-audio' | |
import it_IT from '@uppy/locales/lib/it_IT' | |
import { KiB } from './constants/data-size' | |
import acquireExtjwtBeforeUpload from './handlers/uppy/acquire-extjwt-before-upload' | |
import { getValidUploadTarget } from './utils/get-valid-upload-target' | |
export default function instantiateUppy({ | |
kiwiApi, | |
tokenManager, | |
uploadFileButton, | |
dashboardOptions, | |
tusOptions, | |
uppyOptions, | |
}) { | |
const effectiveDashboardOpts = { | |
trigger: uploadFileButton, | |
proudlyDisplayPoweredByUppy: false, | |
closeModalOnClickOutside: true, | |
note: kiwiApi.state.setting('fileuploader.note'), | |
...dashboardOptions, | |
} | |
const effectiveTusOpts = { | |
endpoint: kiwiApi.state.setting('fileuploader.server'), | |
chunkSize: 512 * KiB, | |
...tusOptions, | |
} | |
const { handlerContext, handleBeforeUpload } = acquireExtjwtBeforeUpload(tokenManager) | |
const effectiveUppyOpts = { | |
autoProceed: false, | |
onBeforeFileAdded: (/* currentFile, files */) => { | |
// throws if invalid, cancelling the file add | |
getValidUploadTarget(kiwiApi) | |
}, | |
locale: it_IT, | |
onBeforeUpload: handleBeforeUpload, | |
restrictions: { | |
maxFileSize: kiwiApi.state.setting('fileuploader.maxFileSize'), | |
}, | |
...uppyOptions, | |
} | |
const uppy = Uppy(effectiveUppyOpts) | |
.use(Dashboard, effectiveDashboardOpts) | |
.use(Webcam, { target: Dashboard, | |
locale: { | |
strings: { | |
pluginNameCamera: 'Webcam', | |
noCameraTitle: 'Webcam non disponibile', | |
noCameraDescription: 'Per scattare foto o registrare video, collegare una webcam', | |
recordingStoppedMaxSize: 'La registrazione è stata interrotta perché la dimensione del file sta per superare il limite', | |
submitRecordedFile: 'Invia file registrato', | |
discardRecordedFile: 'Elimina il file registrato', | |
// Shown before a picture is taken when the `countdown` option is set. | |
smile: 'Sorridi!', | |
// Used as the label for the button that takes a picture. | |
// This is not visibly rendered but is picked up by screen readers. | |
takePicture: 'Fai una foto', | |
// Used as the label for the button that starts a video recording. | |
// This is not visibly rendered but is picked up by screen readers. | |
startRecording: 'Inizia la registrazione video', | |
// Used as the label for the button that stops a video recording. | |
// This is not visibly rendered but is picked up by screen readers. | |
stopRecording: 'Interrompi la registrazione video', | |
// Used as the label for the recording length counter. See the showRecordingLength option. | |
// This is not visibly rendered but is picked up by screen readers. | |
recordingLength: 'Durata della registrazione %{recording_length}', | |
// Title on the “allow access” screen | |
allowAccessTitle: 'Si prega di consentire l\'accesso alla webcam', | |
// Description on the “allow access” screen | |
allowAccessDescription: 'Per scattare foto o registrare video, consenti l\'accesso alla webcam per questo sito.', | |
} | |
} | |
}) | |
.use(Audio, { | |
target: Dashboard, | |
showRecordingLength: true, | |
locale: { | |
strings: { | |
noMicrophoneTitle: 'Microfono non disponibile', | |
noMicrophoneDescription: 'Per registrare messaggi audio, collegare un microfono', | |
recordingStoppedMaxSize: 'La registrazione è stata interrotta perché la dimensione del file sta per superare il limite', | |
submitRecordedFile: 'Invia file registrato', | |
discardRecordedFile: 'Elimina il file registrato', | |
// Used as the label for the button that starts a video recording. | |
// This is not visibly rendered but is picked up by screen readers. | |
startRecording: 'Inizia la registrazione audio', | |
// Used as the label for the button that stops a video recording. | |
// This is not visibly rendered but is picked up by screen readers. | |
stopRecording: 'Interrompi la registrazione audio', | |
// Used as the label for the recording length counter. See the showRecordingLength option. | |
// This is not visibly rendered but is picked up by screen readers. | |
recordingLength: 'Durata della registrazione %{recording_length}', | |
// Title on the “allow access” screen | |
allowAccessTitle: 'Si prega di consentire l\'accesso al microfono', | |
// Description on the “allow access” screen | |
allowAccessDescription: 'Per registrare messaggi audio, consenti l\'accesso al microfono per questo sito.', | |
} | |
}, | |
encoderPath: '/static/waveWorker.min.js' | |
}) | |
.use(Tus, effectiveTusOpts) | |
.run() | |
handlerContext.uppy = uppy // needs reference to uppy which didn't exist until now | |
const dashboard = uppy.getPlugin('Dashboard') | |
return { uppy, dashboard } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment