Skip to content

Commit

Permalink
Improves authentication by allowing usage of Cookie authentication an…
Browse files Browse the repository at this point in the history
…d adds parallel support to Listr file upload tasks (directus-labs#15)
  • Loading branch information
miguelsimoes authored Apr 5, 2021
1 parent 83031e8 commit fab91b7
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 22 deletions.
5 changes: 3 additions & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import dotenv from 'dotenv';
dotenv.config();

const apiV8 = axios.create({
baseURL: process.env.V8_URL,
baseURL: process.env.V8_URL + "/" + process.env.V8_PROJECT_NAME,
headers: {
Authorization: `Bearer ${process.env.V8_TOKEN}`
Authorization: `Bearer ${process.env.V8_TOKEN}`,
Cookie: `directus-${process.env.V8_PROJECT_NAME}-session=${process.env.V8_COOKIE_TOKEN}`
}
});

Expand Down
108 changes: 96 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,27 @@ This tool will copy over:

1) Clone this repo
2) Add a .env file with the following values:
***
You SHOULD use either Cookie or JWT authentication (leaving one or the other empty).

Using `Cookie Authentication` provides you with more time to migrate large amounts of data like the [project files](https://v8.docs.directus.io/guides/files.html#files-thumbnails).

See [documentation](https://v8.docs.directus.io/api/authentication.html#tokens) for more details on obtaining
authentication tokens on Directus v8.
***
```
V8_URL="https://v8.example.com/project"
V8_URL="https://v8.example.com"
V8_PROJECT_NAME="project"
V8_TOKEN="admin"
V8_COOKIE_TOKEN="cookie_value"
V9_URL="https://v9.example.com"
V9_TOKEN="admin"
```
3) Run the `index.js` file: `node index.js`

### NOTE
***
You can exclude collections/database tables from being migrated by using:
```
node index.js -s <table_name> <another_table_name>
```
***
7 changes: 2 additions & 5 deletions tasks/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function uploadFiles(context) {
});
}

return new Listr(tasks);
return new Listr(tasks, { concurrent: tasks.length / 10 });
}

function uploadBatch(page) {
Expand All @@ -54,10 +54,7 @@ function uploadBatch(page) {
task.output = fileRecord.filename_download;

const savedFile = await apiV9.post("/files/import", {
url:
process.env.V8_URL +
"/" +
fileRecord.data.asset_url.split("/").slice(2).join("/"),
url: process.env.V8_URL + "/" + process.env.V8_PROJECT_NAME + "/" + fileRecord.data.asset_url.split("/").slice(2).join("/"),
data: {
filename_download: fileRecord.filename_download,
title: fileRecord.title,
Expand Down

0 comments on commit fab91b7

Please sign in to comment.