Skip to content

Commit

Permalink
繼續實施新的後端
Browse files Browse the repository at this point in the history
  • Loading branch information
igncp committed May 26, 2024
1 parent a641698 commit 96fe225
Show file tree
Hide file tree
Showing 46 changed files with 1,318 additions and 215 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ TOKEN_MAXAGE=3600
TOKEN_EXPIRED_IN=3600
CLIENT_ORIGIN=http://localhost:3000
DATABASE_URL=writing-trainer.db
OPENAI_API_KEY=...
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
echo "Loading mahjong flake"
echo "Loading flake"
use flake
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ module.exports = {
'newline-before-return': 2,
'no-console': 2,
'no-extra-semi': 0,

'no-useless-return': 2,
'object-shorthand': 2,

'padding-line-between-statements': [
'error',
{
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/debug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Debug
on:
push:
branches:
- main
workflow_dispatch:

jobs:
debug:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Dump github context
run: echo "$GITHUB_CONTEXT"
shell: bash
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
2 changes: 2 additions & 0 deletions .github/workflows/deploy-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ on:
- 'Cargo.toml'
- 'scripts/ci/build_docker.sh'
- 'src/backend/**'
workflow_dispatch:

jobs:
build-and-deploy:
if: github.repository == 'igncp/writing-trainer' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-to-ghpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:

jobs:
build-and-deploy:
if: github.repository == 'igncp/writing-trainer' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ USER root
# Required for using the correct GLIBC (v2.38)
RUN echo 'deb http://deb.debian.org/debian unstable main' >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y libssl-dev ca-certificates postgresql sqlite3
&& apt-get install -y libssl-dev ca-certificates sqlite3 glibc-doc

RUN useradd -m -s /bin/bash rust \
&& mkdir -p /app \
Expand Down
6 changes: 3 additions & 3 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

## Backend

- Login with Google (OAuth)
- Sync stats
- Sync saved words
- Add anki support
- Sync stats
- Remove offline records saving support

## Ideas

Expand Down
1 change: 1 addition & 0 deletions migrations/02_texts/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE texts;
10 changes: 10 additions & 0 deletions migrations/02_texts/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE texts (
id VARCHAR NOT NULL PRIMARY KEY,
user_id VARCHAR NOT NULL REFERENCES users(id),
title VARCHAR NULL,
body TEXT NOT NULL,
language VARCHAR NOT NULL,
url VARCHAR NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)
1 change: 1 addition & 0 deletions migrations/03_ankis/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE anki;
9 changes: 9 additions & 0 deletions migrations/03_ankis/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE ankis (
id VARCHAR NOT NULL PRIMARY KEY,
user_id VARCHAR NOT NULL REFERENCES users(id),
front VARCHAR NOT NULL,
back TEXT NOT NULL,
language VARCHAR NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)
30 changes: 30 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-helmet": "^6.1.0",
"react-icons": "^5.2.1",
"react-toastify": "^10.0.5",
"react-use": "^17.3.2"
},
"typeCoverage": {
Expand Down
24 changes: 24 additions & 0 deletions scripts/gen_gql_ts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -e

./node_modules/.bin/graphql-codegen

cp src/react-ui/graphql/gql.ts /tmp/gql.ts
echo "
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
" >src/react-ui/graphql/gql.ts
cat /tmp/gql.ts >>src/react-ui/graphql/gql.ts && rm /tmp/gql.ts

cp src/react-ui/graphql/fragment-masking.ts /tmp/fragment-masking.ts
echo "
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
" >src/react-ui/graphql/fragment-masking.ts
cat /tmp/fragment-masking.ts >>src/react-ui/graphql/fragment-masking.ts && rm /tmp/fragment-masking.ts

./node_modules/.bin/prettier --write 'src/react-ui/graphql/**/*'
./node_modules/.bin/eslint --fix src/react-ui/graphql/

echo "GraphQL types generated successfully!"
6 changes: 4 additions & 2 deletions src/backend/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ impl AppState {

#[derive(Debug, Serialize, Deserialize)]
pub struct TokenClaims {
pub sub: String,
pub iat: usize,
pub access_token: String,
pub exp: usize,
pub iat: usize,
pub id_token: String,
pub sub: String,
}

#[derive(Debug, Deserialize)]
Expand Down
Loading

0 comments on commit 96fe225

Please sign in to comment.