Skip to content

Commit

Permalink
Merge branch 'main' into fix/allow-templates2anki
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu authored Apr 11, 2022
2 parents 7220bb9 + 225f82f commit 368e0ff
Show file tree
Hide file tree
Showing 118 changed files with 1,078 additions and 859 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/auto-bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'Bump Version'

on:
push:
branches:
- 'main'

jobs:
bump-version:
name: 'Bump Version on main'
runs-on: ubuntu-latest

steps:
- name: 'Checkout source code'
uses: 'actions/checkout@v2'
with:
ref: ${{ github.ref }}
- name: 'cat server/package.json'
run: cat ./server/package.json
- name: 'Automated Version Bump'
id: version-bump
uses: 'phips28/gh-action-bump-version@master'
with:
tag-prefix: 'v'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 'cat server/package.json'
run: cat ./server/package.json
- name: 'Output Step'
env:
NEW_TAG: ${{ steps.version-bump.outputs.newTag }}
run: echo "new tag $NEW_TAG"
28 changes: 28 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
push:
tags:
- 'v*'

name: Create Release

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master
- name: Create Release
id: create_release
uses: juitnow/github-action-create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
Changes in this Release
- First Change
- Second Change
draft: false
prerelease: false
4 changes: 2 additions & 2 deletions .github/workflows/build-server.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Smoke Test - Build Server
name: Build Server

on: [push]

Expand All @@ -16,7 +16,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
- name: npm install, build
run: |
cd server
npm install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install and build
- name: npm install and build
run: |
npm --prefix web install
npm --prefix web run build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.2anki.net.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Dokku deploy
uses: vitalyliber/dokku-github-action@v4.0
uses: vitalyliber/dokku-github-action@v7.0
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
HOST: 2anki.net
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/lint-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint server

on: [push]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.14.0]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm run lint
run: |
npm --prefix web install
npm --prefix web run lint
env:
CI: true
File renamed without changes.
50 changes: 50 additions & 0 deletions .github/workflows/publish-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish Docker image

on:
release:
types: [published]

jobs:
push_to_registries:
name: Push Docker image to multiple registries
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: |
alemayhu/notion2anki
ghcr.io/${{ github.repository }}
- name: Build and push Docker images
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ When that is said, if you are not content with Anki, you might want to checkout

## Sponsors

[![Scrimba.com](https://github.com/alemayhu/Notion-to-Anki/raw/master/web/public/sponsors/Scrimba.png)](https://scrimba.com/)
[![Scrimba.com](https://github.com/alemayhu/Notion-to-Anki/raw/main/web/public/sponsors/Scrimba.png)](https://scrimba.com/)

👩🏼‍🎓👨‍🎓️👨‍🏫️👩🏽‍🏫 [Scrimba](https://scrimba.com) - the mind-blowing way to to code!

Expand Down
56 changes: 0 additions & 56 deletions server/lib/User.ts

This file was deleted.

8 changes: 8 additions & 0 deletions server/lib/User/comparePassword.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import bcrypt from "bcryptjs";

export default function comparePassword(
password: string,
hash: string
): boolean {
return bcrypt.compareSync(password, hash);
}
5 changes: 5 additions & 0 deletions server/lib/User/getEmailFromOwner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Knex } from "knex";

export default function getEmailFromOwner(DB: Knex, id: string) {
return DB("users").where({ id }).returning(["email"]).first();
}
8 changes: 8 additions & 0 deletions server/lib/User/getOwnerFromAccessToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Knex } from "knex";

export default function getOwnerFromAccessToken(DB: Knex, token: string) {
return DB("access_tokens")
.where({ token, host: "2anki.net" })
.returning(["owner"])
.first();
}
12 changes: 12 additions & 0 deletions server/lib/User/getQuota.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Knex } from "knex";

export default async function getQuota(DB: Knex, owner: string) {
const allUserUploads = await DB("uploads")
.where({ owner })
.returning(["object_id", "status", "size_mb"]);
let size = 0;
for (const u of allUserUploads) {
size += u.size_mb;
}
return size;
}
5 changes: 5 additions & 0 deletions server/lib/User/hashPassword.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import bcrypt from "bcryptjs";

export default function hashPassword(password: string): string {
return bcrypt.hashSync(password, 12);
}
5 changes: 5 additions & 0 deletions server/lib/User/isPatron.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Knex } from "knex";

export default function isPatron(DB: Knex, id: string) {
return DB("users").where({ id }).returning(["patreon"]).first();
}
13 changes: 13 additions & 0 deletions server/lib/User/updatePassword.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Knex } from "knex";

import hashPassword from "./hashPassword";

export default async function updatePassword(
DB: Knex,
password: any,
reset_token: any
) {
return DB("users")
.where({ reset_token })
.update({ password: hashPassword(password), reset_token: null });
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CardGenerator {
PYTHON(),
createDeckScriptPathARGS,
{ cwd: this.currentDirectory },
(err, stdout, stderr) => {
(err, stdout) => {
if (err) {
console.error(err);
reject(err);
Expand Down
2 changes: 1 addition & 1 deletion server/lib/email/templates/verification.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1 class="title">
<p class="subtitle">
Please verify your account by visiting the link below
</p>
{{link}}
<a class="button is-link" href="{{link}}">verify</a>
<p>If you are having any issues, don't hesitate to ask for help! Reply to this email or join
Discord https://alemayhu.com/discord</p>
<p>Thank you!</p>
Expand Down
12 changes: 6 additions & 6 deletions server/lib/jobs/ConversionJob.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Knex } from "knex";

import { PerformConversion } from "../../routes/notion/convert";
import performConversion from "../../routes/notion/convert/helpers/performConversion";
import TokenHandler from "../misc/TokenHandler";
import NotionAPIWrapper from "../notion/NotionAPIWrapper";
import User from "../../lib/User";

export default class ConversionJob {
db: Knex;
Expand All @@ -19,7 +19,7 @@ export default class ConversionJob {
}

async AllStartedJobs(owner: string) {
return await this.db("jobs")
return this.db("jobs")
.where({ owner, status: "started" })
.returning(["object_id", "status", "size_mb"]);
}
Expand Down Expand Up @@ -58,9 +58,9 @@ export default class ConversionJob {
console.log("jobs", jobs);
jobs.forEach(async (job) => {
try {
const data = await User.GetNotionData(DB, job.owner);
const api = new NotionAPIWrapper(data.token);
PerformConversion(api, job.object_id, job.owner, null, null);
const token = await TokenHandler.GetNotionToken(job.owner);
const api = new NotionAPIWrapper(token!);
await performConversion(api, job.object_id, job.owner, null, null);
} catch (error) {
await new ConversionJob(DB).completed(job.object_id, job.owner);
}
Expand Down
5 changes: 2 additions & 3 deletions server/lib/misc/error.ts → server/lib/misc/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import { TEMPLATE_DIR } from "../constants";
const errorPage = fs
.readFileSync(path.join(TEMPLATE_DIR, "error-message.html"))
.toString();
function ErrorHandler(res: express.Response, err: Error) {

export default function ErrorHandler(res: express.Response, err: Error) {
if (process.env.NODE_ENV === "production") {
Sentry.captureException(err);
}
res.set("Content-Type", "text/html");
const info = errorPage.replace("{err.message}", err.message);
res.status(400).send(info);
}

export default ErrorHandler;
Loading

0 comments on commit 368e0ff

Please sign in to comment.