From b1398bc94c1daac070523c6c82056b8d9be8c649 Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Wed, 22 Nov 2023 11:04:42 -0500 Subject: [PATCH 1/7] Explain `web/` subdirectory. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 478cde6..d9f21bb 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Because Wikidot does not recognize authorship beyond page creation, this has bee This is that service. It stores all the attribution data in AWS DynamoDB, and handles requests without a permanent server using AWS Lambda. +There is a corresponding web frontend, located in `web/`, which provides a convenient way of interacting with this service. However, any REST client can communicate with this service, for instance as part of automated checks or updates. + ### Deployment Locally, you can verify that your code builds in the usual way: From 042124fedb4866e542f0f4af4f531e747008453d Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Wed, 22 Nov 2023 11:09:22 -0500 Subject: [PATCH 2/7] Move api files to subdirectory. --- README.md | 18 +----------------- Cargo.lock => api/Cargo.lock | 0 Cargo.toml => api/Cargo.toml | 0 api/README.md | 19 +++++++++++++++++++ build.rs => api/build.rs | 0 {misc => api/misc}/header.txt | 0 {src => api/src}/attribution.rs | 0 {src => api/src}/handlers.rs | 0 {src => api/src}/macros.rs | 0 {src => api/src}/main.rs | 0 {src => api/src}/object.rs | 0 {src => api/src}/password.rs | 0 {src => api/src}/result.rs | 0 {src => api/src}/utils.rs | 0 web/LICENSE.md | 1 - web/README.md | 10 +++++----- 16 files changed, 25 insertions(+), 23 deletions(-) rename Cargo.lock => api/Cargo.lock (100%) rename Cargo.toml => api/Cargo.toml (100%) create mode 100644 api/README.md rename build.rs => api/build.rs (100%) rename {misc => api/misc}/header.txt (100%) rename {src => api/src}/attribution.rs (100%) rename {src => api/src}/handlers.rs (100%) rename {src => api/src}/macros.rs (100%) rename {src => api/src}/main.rs (100%) rename {src => api/src}/object.rs (100%) rename {src => api/src}/password.rs (100%) rename {src => api/src}/result.rs (100%) rename {src => api/src}/utils.rs (100%) delete mode 120000 web/LICENSE.md diff --git a/README.md b/README.md index d9f21bb..a740cf2 100644 --- a/README.md +++ b/README.md @@ -4,26 +4,10 @@ A service which stores information regarding authorship (attribution) of SCP Wik Because Wikidot does not recognize authorship beyond page creation, this has been a longstanding issue that SCP Wiki branches and sister sites have solved through the use of [attribution-metadata](https://scpwiki.com/attribution-metadata). This was previously a page on the Wikidot site which simply had a table with all the data on it, stored in wikitext. However, this means it is also subject to Wikidot page limitations, and when we passed that limit, it was clear that spending the time on a proper, better solution was the way to go. -This is that service. It stores all the attribution data in AWS DynamoDB, and handles requests without a permanent server using AWS Lambda. +This is that service. Defined in `api/`, this process stores all the attribution data in AWS DynamoDB, and handles requests without a permanent server using AWS Lambda. There is a corresponding web frontend, located in `web/`, which provides a convenient way of interacting with this service. However, any REST client can communicate with this service, for instance as part of automated checks or updates. -### Deployment - -Locally, you can verify that your code builds in the usual way: -``` -cargo check -``` - -The most convenient way to produce artifacts that can be deployed to Lambda is using the [AWS Lambda Rust Runtime](https://github.com/awslabs/aws-lambda-rust-runtime). Using the `cargo lambda` subcommand: -``` -cargo lambda build --release --arm64 --output-format zip -``` - -We target the ARM architecture because we are not using anything specific to x64, and ARM is cheaper and generally more power-efficient. - -The resultant ZIP file (found in `target/lambda/attribution-metadata`) can be uploaded to Lambda via the [console](https://us-east-2.console.aws.amazon.com/lambda/home?region=us-east-2#/functions/AttributionMetadataService). - ### License Available under the terms of the MIT License. diff --git a/Cargo.lock b/api/Cargo.lock similarity index 100% rename from Cargo.lock rename to api/Cargo.lock diff --git a/Cargo.toml b/api/Cargo.toml similarity index 100% rename from Cargo.toml rename to api/Cargo.toml diff --git a/api/README.md b/api/README.md new file mode 100644 index 0000000..23dcb46 --- /dev/null +++ b/api/README.md @@ -0,0 +1,19 @@ +## attribution-metadata API + +This is the backend Lambda service which serves attribution-metadata requests, reading and writing the data from DynamoDB. + +### Deployment + +Locally, you can verify that your code builds in the usual way: +``` +cargo check +``` + +The most convenient way to produce artifacts that can be deployed to Lambda is using the [AWS Lambda Rust Runtime](https://github.com/awslabs/aws-lambda-rust-runtime). Using the `cargo lambda` subcommand: +``` +cargo lambda build --release --arm64 --output-format zip +``` + +We target the ARM architecture because we are not using anything specific to x64, and ARM is cheaper and generally more power-efficient. + +The resultant ZIP file (found in `target/lambda/attribution-metadata`) can be uploaded to Lambda via the [console](https://us-east-2.console.aws.amazon.com/lambda/home?region=us-east-2#/functions/AttributionMetadataService). diff --git a/build.rs b/api/build.rs similarity index 100% rename from build.rs rename to api/build.rs diff --git a/misc/header.txt b/api/misc/header.txt similarity index 100% rename from misc/header.txt rename to api/misc/header.txt diff --git a/src/attribution.rs b/api/src/attribution.rs similarity index 100% rename from src/attribution.rs rename to api/src/attribution.rs diff --git a/src/handlers.rs b/api/src/handlers.rs similarity index 100% rename from src/handlers.rs rename to api/src/handlers.rs diff --git a/src/macros.rs b/api/src/macros.rs similarity index 100% rename from src/macros.rs rename to api/src/macros.rs diff --git a/src/main.rs b/api/src/main.rs similarity index 100% rename from src/main.rs rename to api/src/main.rs diff --git a/src/object.rs b/api/src/object.rs similarity index 100% rename from src/object.rs rename to api/src/object.rs diff --git a/src/password.rs b/api/src/password.rs similarity index 100% rename from src/password.rs rename to api/src/password.rs diff --git a/src/result.rs b/api/src/result.rs similarity index 100% rename from src/result.rs rename to api/src/result.rs diff --git a/src/utils.rs b/api/src/utils.rs similarity index 100% rename from src/utils.rs rename to api/src/utils.rs diff --git a/web/LICENSE.md b/web/LICENSE.md deleted file mode 120000 index 7eabdb1..0000000 --- a/web/LICENSE.md +++ /dev/null @@ -1 +0,0 @@ -../LICENSE.md \ No newline at end of file diff --git a/web/README.md b/web/README.md index 2b01e1a..2cd90b7 100644 --- a/web/README.md +++ b/web/README.md @@ -1,7 +1,11 @@ -## attribution-metadata web +## attribution-metadata Web This is a web UI for interfacing with the `attribution-metadata` Lambda service. It enables users to interact with the API in a user-friendly way, via their browser. +### Internationalization + +This application supports translating into other languages. Simply add a corresponding list of translation strings within the `TRANSLATIONS` block in `src/util/i18n.ts`, connected with the language code. Then, on load, specifying the language code results in that language being loaded in the UI. + ### Deployment First, ensure dependencies are up-to-date: @@ -21,10 +25,6 @@ npm run build You can also use `bun` for these steps instead of `npm`. -### License - -Available under the terms of the MIT License. - ### Special Thanks Thanks to smlt for contributing the initial version of this web frontend. From 4a30a35d090dbd0669b9b740991ef002c5a5c3ca Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Wed, 22 Nov 2023 11:18:03 -0500 Subject: [PATCH 3/7] Update build for both components. --- .../workflows/{check.yaml => api-check.yaml} | 7 ++-- .github/workflows/web-check.yaml | 32 +++++++++++++++++++ .../{deploy.yaml => web-deploy.yaml} | 0 3 files changed, 34 insertions(+), 5 deletions(-) rename .github/workflows/{check.yaml => api-check.yaml} (91%) create mode 100644 .github/workflows/web-check.yaml rename .github/workflows/{deploy.yaml => web-deploy.yaml} (100%) diff --git a/.github/workflows/check.yaml b/.github/workflows/api-check.yaml similarity index 91% rename from .github/workflows/check.yaml rename to .github/workflows/api-check.yaml index bb783c6..fce3c1d 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/api-check.yaml @@ -3,11 +3,8 @@ name: 'Rust Build' on: push: paths: - - '.github/workflows/check.yaml' - - 'Cargo.toml' - - 'Cargo.lock' - - 'src/**' - - 'build.rs' + - '.github/workflows/api-check.yaml' + - 'api/**' jobs: build: diff --git a/.github/workflows/web-check.yaml b/.github/workflows/web-check.yaml new file mode 100644 index 0000000..3ef9e7d --- /dev/null +++ b/.github/workflows/web-check.yaml @@ -0,0 +1,32 @@ +name: 'Web Build' + +on: + push: + paths: + - '.github/workflows/web-check.yaml' + - 'web/**' + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Node.js Setup + uses: actions/setup-node@v3 + with: + node-version: '21.x' + + - name: NPM Dependencies + run: npm ci + + - name: NPM Cache + uses: actions/cache@v2 + with: + path: ./node_modules + key: ${{ runner.os }}-node-${{ hashFiles('package.json') }} + + - name: Build + run: npm run build diff --git a/.github/workflows/deploy.yaml b/.github/workflows/web-deploy.yaml similarity index 100% rename from .github/workflows/deploy.yaml rename to .github/workflows/web-deploy.yaml From 8b8aaacf1a57a6029820bed05a89e412d1e7e4e5 Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Wed, 22 Nov 2023 11:18:26 -0500 Subject: [PATCH 4/7] Build app before deploy. --- .github/workflows/web-check.yaml | 2 +- .github/workflows/web-deploy.yaml | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/web-check.yaml b/.github/workflows/web-check.yaml index 3ef9e7d..0d71128 100644 --- a/.github/workflows/web-check.yaml +++ b/.github/workflows/web-check.yaml @@ -28,5 +28,5 @@ jobs: path: ./node_modules key: ${{ runner.os }}-node-${{ hashFiles('package.json') }} - - name: Build + - name: Build app run: npm run build diff --git a/.github/workflows/web-deploy.yaml b/.github/workflows/web-deploy.yaml index cd3babe..553ae1d 100644 --- a/.github/workflows/web-deploy.yaml +++ b/.github/workflows/web-deploy.yaml @@ -31,10 +31,21 @@ jobs: - name: Setup Pages uses: actions/configure-pages@v3 + - name: Node.js Setup + uses: actions/setup-node@v3 + with: + node-version: '21.x' + + - name: NPM Dependencies + run: npm ci + + - name: Build app + run: npm run build + - name: Upload artifact uses: actions/upload-pages-artifact@v2 with: - path: web + path: web/dist - name: Deploy to GitHub Pages id: deployment From fc78da5daf2f4fc8702c38898954460193e6a92d Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Wed, 22 Nov 2023 11:21:04 -0500 Subject: [PATCH 5/7] Change directory before build. --- .github/workflows/api-check.yaml | 10 +++++----- .github/workflows/web-check.yaml | 4 ++-- .github/workflows/web-deploy.yaml | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/api-check.yaml b/.github/workflows/api-check.yaml index fce3c1d..ff7ce35 100644 --- a/.github/workflows/api-check.yaml +++ b/.github/workflows/api-check.yaml @@ -27,11 +27,11 @@ jobs: path: | ~/.cargo/registry ~/.cargo/git - ./target + ./api/target key: ${{ runner.os }}-rust-${{ hashFiles('Cargo.toml') }} - name: Build - run: cargo build + run: cd api && cargo build clippy_lint: name: Lint @@ -56,11 +56,11 @@ jobs: path: | ~/.cargo/registry ~/.cargo/git - ./target + ./api/target key: ${{ runner.os }}-rust-lint-${{ hashFiles('Cargo.toml') }} - name: Rustfmt - run: cargo fmt --all -- --check + run: cd api && cargo fmt --all -- --check - name: Clippy - run: cargo clippy + run: cd api && cargo clippy diff --git a/.github/workflows/web-check.yaml b/.github/workflows/web-check.yaml index 0d71128..196fe9b 100644 --- a/.github/workflows/web-check.yaml +++ b/.github/workflows/web-check.yaml @@ -20,7 +20,7 @@ jobs: node-version: '21.x' - name: NPM Dependencies - run: npm ci + run: cd web && npm ci - name: NPM Cache uses: actions/cache@v2 @@ -29,4 +29,4 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('package.json') }} - name: Build app - run: npm run build + run: cd web && npm run build diff --git a/.github/workflows/web-deploy.yaml b/.github/workflows/web-deploy.yaml index 553ae1d..e960cd8 100644 --- a/.github/workflows/web-deploy.yaml +++ b/.github/workflows/web-deploy.yaml @@ -37,10 +37,10 @@ jobs: node-version: '21.x' - name: NPM Dependencies - run: npm ci + run: cd web && npm ci - name: Build app - run: npm run build + run: cd web && npm run build - name: Upload artifact uses: actions/upload-pages-artifact@v2 From 1466803ceeb7600b6c076ac3d77ef74c294a57f5 Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Wed, 22 Nov 2023 11:22:28 -0500 Subject: [PATCH 6/7] Lower node version. --- .github/workflows/web-check.yaml | 2 +- .github/workflows/web-deploy.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/web-check.yaml b/.github/workflows/web-check.yaml index 196fe9b..7a915cc 100644 --- a/.github/workflows/web-check.yaml +++ b/.github/workflows/web-check.yaml @@ -17,7 +17,7 @@ jobs: - name: Node.js Setup uses: actions/setup-node@v3 with: - node-version: '21.x' + node-version: '20.x' - name: NPM Dependencies run: cd web && npm ci diff --git a/.github/workflows/web-deploy.yaml b/.github/workflows/web-deploy.yaml index e960cd8..2e2238b 100644 --- a/.github/workflows/web-deploy.yaml +++ b/.github/workflows/web-deploy.yaml @@ -34,7 +34,7 @@ jobs: - name: Node.js Setup uses: actions/setup-node@v3 with: - node-version: '21.x' + node-version: '20.x' - name: NPM Dependencies run: cd web && npm ci From 3db5368c1ce17fa0b159853775edeba4bc6c1dda Mon Sep 17 00:00:00 2001 From: Emmie Maeda Date: Wed, 22 Nov 2023 11:24:25 -0500 Subject: [PATCH 7/7] Fix hash paths. --- .github/workflows/api-check.yaml | 4 ++-- .github/workflows/web-check.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/api-check.yaml b/.github/workflows/api-check.yaml index ff7ce35..8981816 100644 --- a/.github/workflows/api-check.yaml +++ b/.github/workflows/api-check.yaml @@ -28,7 +28,7 @@ jobs: ~/.cargo/registry ~/.cargo/git ./api/target - key: ${{ runner.os }}-rust-${{ hashFiles('Cargo.toml') }} + key: ${{ runner.os }}-rust-${{ hashFiles('api/Cargo.toml') }} - name: Build run: cd api && cargo build @@ -57,7 +57,7 @@ jobs: ~/.cargo/registry ~/.cargo/git ./api/target - key: ${{ runner.os }}-rust-lint-${{ hashFiles('Cargo.toml') }} + key: ${{ runner.os }}-rust-lint-${{ hashFiles('api/Cargo.toml') }} - name: Rustfmt run: cd api && cargo fmt --all -- --check diff --git a/.github/workflows/web-check.yaml b/.github/workflows/web-check.yaml index 7a915cc..8bffcaf 100644 --- a/.github/workflows/web-check.yaml +++ b/.github/workflows/web-check.yaml @@ -26,7 +26,7 @@ jobs: uses: actions/cache@v2 with: path: ./node_modules - key: ${{ runner.os }}-node-${{ hashFiles('package.json') }} + key: ${{ runner.os }}-node-${{ hashFiles('web/package.json') }} - name: Build app run: cd web && npm run build