mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
Use long-lived refresh tokens for dropbox
This commit is contained in:
parent
cd7005a13a
commit
88228a8dc2
@ -1,18 +1,39 @@
|
||||
import { createProductSKUs } from 'lib/helpers/skus';
|
||||
import { getProducts } from 'lib/shopify';
|
||||
|
||||
import { Dropbox } from 'dropbox';
|
||||
import { Dropbox, DropboxResponse, files } from 'dropbox';
|
||||
|
||||
// how to get new Dropbox refresh token
|
||||
// 1. go to https://www.dropbox.com/oauth2/authorize?client_id=YOUR_APP_KEY&token_access_type=offline&response_type=code&redirect_uri=https://www.dropbox.com/1/oauth2/display_token
|
||||
// 2. copy code from URL after redirect
|
||||
// 3. curl
|
||||
// curl -X POST https://api.dropboxapi.com/oauth2/token \
|
||||
// -d 'grant_type=authorization_code' \
|
||||
// -d 'code=CODE_HERE' \
|
||||
// -d 'client_id=CLIENT_ID' \
|
||||
// -d 'client_secret=CLIENT_SECRET' \
|
||||
// -d 'redirect_uri=https://www.dropbox.com/1/oauth2/display_token'
|
||||
|
||||
|
||||
export default async function SKUCheckPage() {
|
||||
const products = await getProducts({});
|
||||
|
||||
let dbxFiles: DropboxResponse<files.ListFolderResult> | undefined;
|
||||
let dbxError: string | undefined;
|
||||
|
||||
try {
|
||||
const dbx = new Dropbox({
|
||||
accessToken: process.env.DROPBOX_TOKEN
|
||||
clientId: process.env.DROPBOX_APP_KEY,
|
||||
clientSecret: process.env.DROPBOX_APP_SECRET,
|
||||
refreshToken: process.env.DROPBOX_REFRESH_TOKEN
|
||||
});
|
||||
|
||||
const dbxFiles = await dbx.filesListFolder({
|
||||
dbxFiles = await dbx.filesListFolder({
|
||||
path: '/scape squared/004 print ready - print files'
|
||||
});
|
||||
} catch (e) {
|
||||
dbxError = e + ""
|
||||
}
|
||||
|
||||
// sabotage?
|
||||
// dbxFiles.result.entries.splice(5, 1);
|
||||
@ -25,7 +46,7 @@ export default async function SKUCheckPage() {
|
||||
// sabotage?
|
||||
// product.variants[3]!.sku = 'SCSQ10001_STTU781_M_C002_B_NT';
|
||||
|
||||
const productFiles = dbxFiles.result.entries
|
||||
const productFiles = dbxFiles?.result.entries
|
||||
.filter((file) => file.name.startsWith(skus[0]!.split('_')[0]!))
|
||||
|
||||
return (
|
||||
@ -34,10 +55,10 @@ export default async function SKUCheckPage() {
|
||||
<div
|
||||
className={
|
||||
'mb-4 lg:col-span-4 lg:col-start-3 rounded ' +
|
||||
(productFiles.length !== 2 ? 'bg-amber-300' : '')
|
||||
(productFiles?.length !== 2 ? 'bg-amber-300' : '')
|
||||
}
|
||||
>
|
||||
Dropbox: {productFiles?.map(file => file.name).join(", ")}
|
||||
Dropbox: {productFiles?.map(file => file.name).join(", ")}{dbxError}
|
||||
</div>
|
||||
{product.variants.map((variant, i) => (
|
||||
<>
|
||||
|
Loading…
x
Reference in New Issue
Block a user