-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial poc * improvements - split into two plugins - implement photos picker - auto login - save access token in local storage - document - handle photos/files picked and send to companion - add new hook useStore for making it easier to use localStorage data in react - add new hook useUppyState for making it easier to use uppy state from react - add new hook useUppyPluginState for making it easier to plugin state from react - fix css error * implement picker in companion * type todo * fix ts error which occurs in dev when js has been built before build:ts gets called * reuse docs * imrpve type safety * simplify async wrapper * improve doc * fix lint * fix build error * check if token is valid * fix broken logging code * pull logic out from react component * remove docs * improve auth ui * fix bug * remove unused useUppyState * try to fix build error
- Loading branch information
Showing
62 changed files
with
1,679 additions
and
184 deletions.
There are no files selected for viewing
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
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
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
4 changes: 2 additions & 2 deletions
4
packages/@uppy/companion-client/src/CompanionPluginOptions.ts
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
/** | ||
* This module serves as an Async wrapper for LocalStorage | ||
* Why? Because the Provider API `storage` option allows an async storage | ||
*/ | ||
export function setItem(key: string, value: string): Promise<void> { | ||
return new Promise((resolve) => { | ||
localStorage.setItem(key, value) | ||
resolve() | ||
}) | ||
export async function setItem(key: string, value: string): Promise<void> { | ||
localStorage.setItem(key, value) | ||
} | ||
|
||
export function getItem(key: string): Promise<string | null> { | ||
return Promise.resolve(localStorage.getItem(key)) | ||
export async function getItem(key: string): Promise<string | null> { | ||
return localStorage.getItem(key) | ||
} | ||
|
||
export function removeItem(key: string): Promise<void> { | ||
return new Promise((resolve) => { | ||
localStorage.removeItem(key) | ||
resolve() | ||
}) | ||
export async function removeItem(key: string): Promise<void> { | ||
localStorage.removeItem(key) | ||
} |
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
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
57 changes: 57 additions & 0 deletions
57
packages/@uppy/companion/src/server/controllers/googlePicker.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const express = require('express') | ||
const assert = require('node:assert') | ||
|
||
const { startDownUpload } = require('../helpers/upload') | ||
const { validateURL } = require('../helpers/request') | ||
const { getURLMeta } = require('../helpers/request') | ||
const logger = require('../logger') | ||
const { downloadURL } = require('../download') | ||
const { getGoogleFileSize, streamGoogleFile } = require('../provider/google/drive'); | ||
|
||
|
||
const getAuthHeader = (token) => ({ authorization: `Bearer ${token}` }); | ||
|
||
/** | ||
* | ||
* @param {object} req expressJS request object | ||
* @param {object} res expressJS response object | ||
*/ | ||
const get = async (req, res) => { | ||
try { | ||
logger.debug('Google Picker file import handler running', null, req.id) | ||
|
||
const allowLocalUrls = false | ||
|
||
const { accessToken, platform, fileId } = req.body | ||
|
||
assert(platform === 'drive' || platform === 'photos'); | ||
|
||
const getSize = async () => { | ||
if (platform === 'drive') { | ||
return getGoogleFileSize({ id: fileId, token: accessToken }) | ||
} | ||
const { size } = await getURLMeta(req.body.url, allowLocalUrls, { headers: getAuthHeader(accessToken) }) | ||
return size | ||
} | ||
|
||
if (platform === 'photos' && !validateURL(req.body.url, allowLocalUrls)) { | ||
res.status(400).json({ error: 'Invalid URL' }) | ||
return | ||
} | ||
|
||
const download = () => { | ||
if (platform === 'drive') { | ||
return streamGoogleFile({ token: accessToken, id: fileId }) | ||
} | ||
return downloadURL(req.body.url, allowLocalUrls, req.id, { headers: getAuthHeader(accessToken) }) | ||
} | ||
|
||
await startDownUpload({ req, res, getSize, download }) | ||
} catch (err) { | ||
logger.error(err, 'controller.googlePicker.error', req.id) | ||
res.status(err.status || 500).json({ message: 'failed to fetch Google Picker URL' }) | ||
} | ||
} | ||
|
||
module.exports = () => express.Router() | ||
.post('/get', express.json(), get) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const logger = require('./logger') | ||
const { getProtectedGot } = require('./helpers/request') | ||
const { prepareStream } = require('./helpers/utils') | ||
|
||
/** | ||
* Downloads the content in the specified url, and passes the data | ||
* to the callback chunk by chunk. | ||
* | ||
* @param {string} url | ||
* @param {boolean} allowLocalIPs | ||
* @param {string} traceId | ||
* @returns {Promise} | ||
*/ | ||
const downloadURL = async (url, allowLocalIPs, traceId, options) => { | ||
try { | ||
const protectedGot = await getProtectedGot({ allowLocalIPs }) | ||
const stream = protectedGot.stream.get(url, { responseType: 'json', ...options }) | ||
const { size } = await prepareStream(stream) | ||
return { stream, size } | ||
} catch (err) { | ||
logger.error(err, 'controller.url.download.error', traceId) | ||
throw err | ||
} | ||
} | ||
|
||
module.exports = { | ||
downloadURL, | ||
} |
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
Oops, something went wrong.