Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
env:
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
NOTION_DATABASE_ID: ${{ secrets.NOTION_DATABASE_ID }}
AZURE_BLOB_CONNECTION_STRING: ${{ secrets.AZURE_BLOB_CONNECTION_STRING }}

- name: Save blog cache
uses: actions/cache/save@v3
Expand Down
3 changes: 2 additions & 1 deletion api/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NOTION_TOKEN=__TOKEN__
NOTION_DATABASE_ID=__DATABASE_ID__
NOTION_DATABASE_ID=__DATABASE_ID__
AZURE_BLOB_CONNECTION_STRING=__AZURE_BLOB_CONNECTION_STRING__
229 changes: 228 additions & 1 deletion api/package-lock.json

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

4 changes: 3 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"typescript": "^5.1.6"
},
"dependencies": {
"@azure/storage-blob": "^12.15.0",
"@notionhq/client": "^2.2.11",
"lowdb": "^6.0.1",
"notion-to-md": "^3.1.1",
"pinyin": "^3.0.0-alpha.5"
"pinyin": "^3.0.0-alpha.5",
"uuid": "^9.0.0"
}
}
22 changes: 22 additions & 0 deletions api/src/blob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ContainerClient } from "@azure/storage-blob";

const containerUrl = "https://chaoszhblob.blob.core.windows.net/blog"
const containerClient = new ContainerClient(
process.env.AZURE_BLOB_CONNECTION_STRING!,
"blog"
);

export function CreateCopyToBlobTask(blob: string, sourceUrl: string): [string, Promise<any>] {
console.log(`[CopyToBlob ${blob}] Start copy ${sourceUrl}`);
let blobClient = containerClient.getBlobClient(blob);
let task = blobClient.beginCopyFromURL(sourceUrl);
return [`${containerUrl}/${blob}`, new Promise((resolve, reject) => {
task.then((res) => {
console.log(`[CopyToBlob ${blob}] Succeed to copy`);
resolve(res);
}).catch((err) => {
console.log(`[CopyToBlob ${blob}]: Failed to copy, err: ${err}`);
reject(err);
});
})];
}
5 changes: 3 additions & 2 deletions api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Page } from "./model"
import { PageObjectResponse } from "@notionhq/client/build/src/api-endpoints"
import * as fs from 'fs';
import { notion, n2m } from "./notion";
import { notion, n2m, copyToBlobTasks } from "./notion";

const databaseId = process.env.NOTION_DATABASE_ID

Expand Down Expand Up @@ -44,11 +44,12 @@ async function PersistPages(pages: Page[]) {
}

// update cached pages according to last_edit_time
let tasks: Promise<void>[] = [];
let tasks: Promise<any>[] = [];
for (let page of pages)
{
tasks.push(PersistSinglePage(page));
}
tasks.push(...copyToBlobTasks);
for (let task of tasks)
{
await task;
Expand Down
Loading