mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 07:56:59 +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 { createProductSKUs } from 'lib/helpers/skus';
|
||||||
import { getProducts } from 'lib/shopify';
|
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() {
|
export default async function SKUCheckPage() {
|
||||||
const products = await getProducts({});
|
const products = await getProducts({});
|
||||||
|
|
||||||
|
let dbxFiles: DropboxResponse<files.ListFolderResult> | undefined;
|
||||||
|
let dbxError: string | undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
const dbx = new Dropbox({
|
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'
|
path: '/scape squared/004 print ready - print files'
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
dbxError = e + ""
|
||||||
|
}
|
||||||
|
|
||||||
// sabotage?
|
// sabotage?
|
||||||
// dbxFiles.result.entries.splice(5, 1);
|
// dbxFiles.result.entries.splice(5, 1);
|
||||||
@ -25,7 +46,7 @@ export default async function SKUCheckPage() {
|
|||||||
// sabotage?
|
// sabotage?
|
||||||
// product.variants[3]!.sku = 'SCSQ10001_STTU781_M_C002_B_NT';
|
// 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]!))
|
.filter((file) => file.name.startsWith(skus[0]!.split('_')[0]!))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -34,10 +55,10 @@ export default async function SKUCheckPage() {
|
|||||||
<div
|
<div
|
||||||
className={
|
className={
|
||||||
'mb-4 lg:col-span-4 lg:col-start-3 rounded ' +
|
'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>
|
</div>
|
||||||
{product.variants.map((variant, i) => (
|
{product.variants.map((variant, i) => (
|
||||||
<>
|
<>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user