split todo backend from frontend
116
backend/Cargo.lock → Cargo.lock
generated
|
@ -17,6 +17,15 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ansi_term"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||||
|
dependencies = [
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.42"
|
version = "1.0.42"
|
||||||
|
@ -245,6 +254,7 @@ dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel",
|
"diesel",
|
||||||
|
"diesel-tracing",
|
||||||
"diesel_migrations",
|
"diesel_migrations",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"fern",
|
"fern",
|
||||||
|
@ -261,6 +271,10 @@ dependencies = [
|
||||||
"tokio 1.9.0",
|
"tokio 1.9.0",
|
||||||
"tokio-diesel",
|
"tokio-diesel",
|
||||||
"tower",
|
"tower",
|
||||||
|
"tower-http",
|
||||||
|
"tracing",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-subscriber",
|
||||||
"url",
|
"url",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
@ -528,12 +542,25 @@ dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel_derives",
|
"diesel_derives",
|
||||||
|
"ipnetwork",
|
||||||
|
"libc",
|
||||||
"pq-sys",
|
"pq-sys",
|
||||||
"r2d2",
|
"r2d2",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "diesel-tracing"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1c039d591e23293c9d9682139758ea499e2a56b27c2ef38704c8f1dc5e2044ad"
|
||||||
|
dependencies = [
|
||||||
|
"diesel",
|
||||||
|
"ipnetwork",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "diesel_derives"
|
name = "diesel_derives"
|
||||||
version = "1.4.1"
|
version = "1.4.1"
|
||||||
|
@ -1014,6 +1041,15 @@ version = "2.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9"
|
checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ipnetwork"
|
||||||
|
version = "0.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4088d739b183546b239688ddbc79891831df421773df95e236daf7867866d355"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "0.4.7"
|
version = "0.4.7"
|
||||||
|
@ -1079,6 +1115,15 @@ dependencies = [
|
||||||
"value-bag",
|
"value-bag",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "matchers"
|
||||||
|
version = "0.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1"
|
||||||
|
dependencies = [
|
||||||
|
"regex-automata",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matches"
|
name = "matches"
|
||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
|
@ -1586,6 +1631,15 @@ dependencies = [
|
||||||
"regex-syntax",
|
"regex-syntax",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.1.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||||
|
dependencies = [
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-syntax"
|
name = "regex-syntax"
|
||||||
version = "0.6.25"
|
version = "0.6.25"
|
||||||
|
@ -1826,6 +1880,15 @@ dependencies = [
|
||||||
"opaque-debug",
|
"opaque-debug",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sharded-slab"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "740223c51853f3145fe7c90360d2d4232f2b62e3449489c207eccde818979982"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "signal-hook-registry"
|
name = "signal-hook-registry"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
@ -1914,6 +1977,15 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thread_local"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.1.44"
|
version = "0.1.44"
|
||||||
|
@ -2096,6 +2168,7 @@ dependencies = [
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2143,6 +2216,49 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-log"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6923477a48e41c1951f1999ef8bb5a3023eb723ceadafe78ffb65dc366761e3"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-serde"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"tracing-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-subscriber"
|
||||||
|
version = "0.2.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9cbe87a2fa7e35900ce5de20220a582a9483a7063811defce79d7cbd59d4cfe"
|
||||||
|
dependencies = [
|
||||||
|
"ansi_term",
|
||||||
|
"chrono",
|
||||||
|
"lazy_static",
|
||||||
|
"matchers",
|
||||||
|
"regex",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"sharded-slab",
|
||||||
|
"smallvec",
|
||||||
|
"thread_local",
|
||||||
|
"tracing",
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "try-lock"
|
name = "try-lock"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
|
@ -13,6 +13,7 @@ async-std = {version = "1.9.0", features = ["attributes"]}
|
||||||
axum = {version = "0.1.1", features = ["headers"]}
|
axum = {version = "0.1.1", features = ["headers"]}
|
||||||
chrono = {version = "0.4.0", features = ["serde"]}
|
chrono = {version = "0.4.0", features = ["serde"]}
|
||||||
diesel = {version = "1.4.7", features = ["postgres", "chrono", "serde_json", "r2d2", "uuidv07"]}
|
diesel = {version = "1.4.7", features = ["postgres", "chrono", "serde_json", "r2d2", "uuidv07"]}
|
||||||
|
diesel-tracing = {version = "0.1.5", features = ["postgres"]}
|
||||||
diesel_migrations = {version = "1.4.0"}
|
diesel_migrations = {version = "1.4.0"}
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
fern = "0.6.0"
|
fern = "0.6.0"
|
||||||
|
@ -29,5 +30,9 @@ serde_json = "1.0.66"
|
||||||
tokio = {version = "1.9.0", features = ["full"]}
|
tokio = {version = "1.9.0", features = ["full"]}
|
||||||
tokio-diesel = {git = "https://github.com/mehcode/tokio-diesel", version = "0.3.0"}
|
tokio-diesel = {git = "https://github.com/mehcode/tokio-diesel", version = "0.3.0"}
|
||||||
tower = {version = "0.4.6", features = ["full"]}
|
tower = {version = "0.4.6", features = ["full"]}
|
||||||
|
tower-http = {version = "0.1.1", features = ["trace"]}
|
||||||
|
tracing = {version = "0.1.26", features = ["log-always"]}
|
||||||
|
tracing-log = {version = "0.1.2", features = ["log-tracer"]}
|
||||||
|
tracing-subscriber = {version = "0.2.20", features = ["fmt"]}
|
||||||
url = "2.2.2"
|
url = "2.2.2"
|
||||||
uuid = {version = "0.8.2", features = ["serde", "v4"]}
|
uuid = {version = "0.8.2", features = ["serde", "v4"]}
|
|
@ -1,3 +0,0 @@
|
||||||
DATABASE_URL=postgres://postgres@localhost/todo_dev
|
|
||||||
LOG_LEVEL=DEBUG
|
|
||||||
PORT=8080
|
|
|
@ -1,30 +0,0 @@
|
||||||
use crate::diesel::PgConnection;
|
|
||||||
use crate::logging::LogService;
|
|
||||||
use async_redis_session::RedisSessionStore;
|
|
||||||
use axum::{prelude::*, routing::BoxRoute, AddExtensionLayer};
|
|
||||||
use diesel::r2d2::{ConnectionManager, Pool};
|
|
||||||
use std::env;
|
|
||||||
|
|
||||||
pub mod block;
|
|
||||||
pub mod discord;
|
|
||||||
pub mod user;
|
|
||||||
|
|
||||||
// this should never get called, because the reverse
|
|
||||||
// proxy on caddy should only direct calls from /api
|
|
||||||
async fn root() -> &'static str {
|
|
||||||
"Hi"
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_routes(pool: Pool<ConnectionManager<PgConnection>>) -> BoxRoute<Body> {
|
|
||||||
let redis_url = env::var("REDIS_URL").unwrap_or(String::from("redis://localhost"));
|
|
||||||
|
|
||||||
let client = redis::Client::open(redis_url.as_str()).expect("Could not create redis client.");
|
|
||||||
route("/", get(root))
|
|
||||||
.nest("/discord", discord::get_routes())
|
|
||||||
.layer(tower::layer::layer_fn(|service| LogService { service }))
|
|
||||||
.layer(AddExtensionLayer::new(RedisSessionStore::from_client(
|
|
||||||
client,
|
|
||||||
)))
|
|
||||||
.layer(AddExtensionLayer::new(pool))
|
|
||||||
.boxed()
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
use std::fmt;
|
|
||||||
use std::task::{Context, Poll};
|
|
||||||
use tower::Service;
|
|
||||||
|
|
||||||
pub struct LogService<S> {
|
|
||||||
pub service: S,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S, Request> Service<Request> for LogService<S>
|
|
||||||
where
|
|
||||||
S: Service<Request>,
|
|
||||||
Request: fmt::Debug,
|
|
||||||
{
|
|
||||||
type Response = S::Response;
|
|
||||||
type Error = S::Error;
|
|
||||||
type Future = S::Future;
|
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
||||||
self.service.poll_ready(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, request: Request) -> Self::Future {
|
|
||||||
log::debug!("request = {:?}", request);
|
|
||||||
self.service.call(request)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
use axum::prelude::*;
|
|
||||||
use std::net::SocketAddr;
|
|
||||||
|
|
||||||
use diesel::{
|
|
||||||
prelude::*,
|
|
||||||
r2d2::{ConnectionManager, Pool},
|
|
||||||
};
|
|
||||||
use dotenv::dotenv;
|
|
||||||
use std::env;
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate diesel;
|
|
||||||
extern crate redis;
|
|
||||||
|
|
||||||
mod endpoints;
|
|
||||||
pub mod helpers;
|
|
||||||
pub mod logging;
|
|
||||||
pub mod migration;
|
|
||||||
pub mod models;
|
|
||||||
pub mod schema;
|
|
||||||
pub mod tests;
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() {
|
|
||||||
dotenv().ok();
|
|
||||||
let _ = setup_logger();
|
|
||||||
|
|
||||||
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set");
|
|
||||||
|
|
||||||
migration::run_migrations(&db_url);
|
|
||||||
let manager = ConnectionManager::<PgConnection>::new(&db_url);
|
|
||||||
let pool = Pool::builder()
|
|
||||||
.build(manager)
|
|
||||||
.expect("Could not build connection pool");
|
|
||||||
|
|
||||||
let root = route("/api", endpoints::get_routes(pool));
|
|
||||||
|
|
||||||
let port = env::var("PORT").unwrap_or(String::from("8000"));
|
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], port.parse().unwrap_or(8000)));
|
|
||||||
|
|
||||||
log::info!("started listening on {:?}", addr);
|
|
||||||
hyper::Server::bind(&addr)
|
|
||||||
.serve(root.into_make_service())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setup_logger() -> Result<(), fern::InitError> {
|
|
||||||
let log_level = env::var("LOG_LEVEL").unwrap_or(String::from("INFO"));
|
|
||||||
fern::Dispatch::new()
|
|
||||||
.format(|out, message, record| {
|
|
||||||
out.finish(format_args!(
|
|
||||||
"{} <{}> [{}] {}",
|
|
||||||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
|
|
||||||
record.file().unwrap_or(record.target()),
|
|
||||||
record.level(),
|
|
||||||
message
|
|
||||||
))
|
|
||||||
})
|
|
||||||
.level(log::LevelFilter::from_str(log_level.as_str()).unwrap_or(log::LevelFilter::Info))
|
|
||||||
.chain(std::io::stdout())
|
|
||||||
.chain(fern::log_file("latest.log")?)
|
|
||||||
.apply()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
5
frontend/.gitignore
vendored
|
@ -1,5 +0,0 @@
|
||||||
.DS_Store
|
|
||||||
/node_modules/
|
|
||||||
/src/node_modules/@sapper/
|
|
||||||
yarn-error.log
|
|
||||||
/__sapper__/
|
|
|
@ -1,16 +0,0 @@
|
||||||
arrowParens: 'always'
|
|
||||||
bracketSpacing: true
|
|
||||||
endOfLine: 'lf'
|
|
||||||
htmlWhitespaceSensitivity: 'css'
|
|
||||||
insertPragma: false
|
|
||||||
jsxBracketSameLine: true
|
|
||||||
jsxSingleQuote: true
|
|
||||||
printWidth: 120
|
|
||||||
proseWrap: 'preserve'
|
|
||||||
quoteProps: 'consistent'
|
|
||||||
requirePragma: false
|
|
||||||
semi: true
|
|
||||||
singleQuote: true
|
|
||||||
tabWidth: 2
|
|
||||||
trailingComma: 'none'
|
|
||||||
useTabs: false
|
|
|
@ -1,11 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
"stories": [
|
|
||||||
"../src/**/*.stories.mdx",
|
|
||||||
"../src/**/*.stories.@(js|jsx|ts|tsx|svelte)"
|
|
||||||
],
|
|
||||||
"addons": [
|
|
||||||
"@storybook/addon-links",
|
|
||||||
"@storybook/addon-essentials",
|
|
||||||
"@storybook/addon-svelte-csf"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
export const parameters = {
|
|
||||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
|
||||||
controls: {
|
|
||||||
matchers: {
|
|
||||||
color: /(background|color)$/i,
|
|
||||||
date: /Date$/,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
# Todo Frontend
|
|
39
frontend/src_old/ambient.d.ts
vendored
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* These declarations tell TypeScript that we allow import of images, e.g.
|
|
||||||
* ```
|
|
||||||
<script lang='ts'>
|
|
||||||
import successkid from 'images/successkid.jpg';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<img src="{successkid}">
|
|
||||||
```
|
|
||||||
*/
|
|
||||||
declare module "*.gif" {
|
|
||||||
const value: string;
|
|
||||||
export default value;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "*.jpg" {
|
|
||||||
const value: string;
|
|
||||||
export default value;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "*.jpeg" {
|
|
||||||
const value: string;
|
|
||||||
export default value;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "*.png" {
|
|
||||||
const value: string;
|
|
||||||
export default value;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "*.svg" {
|
|
||||||
const value: string;
|
|
||||||
export default value;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "*.webp" {
|
|
||||||
const value: string;
|
|
||||||
export default value;
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
import * as sapper from '@sapper/app';
|
|
||||||
|
|
||||||
sapper.start({
|
|
||||||
target: document.querySelector('#sapper')
|
|
||||||
});
|
|
|
@ -1,42 +0,0 @@
|
||||||
<script>
|
|
||||||
import './button.css';
|
|
||||||
import { createEventDispatcher } from 'svelte';
|
|
||||||
/**
|
|
||||||
* Is this the principal call to action on the page?
|
|
||||||
*/
|
|
||||||
export let primary = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* What background color to use
|
|
||||||
*/
|
|
||||||
export let backgroundColor;
|
|
||||||
/**
|
|
||||||
* How large should the button be?
|
|
||||||
*/
|
|
||||||
export let size = 'medium';
|
|
||||||
/**
|
|
||||||
* Button contents
|
|
||||||
*/
|
|
||||||
export let label = '';
|
|
||||||
|
|
||||||
let mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
||||||
|
|
||||||
let style = backgroundColor ? `background-color: ${backgroundColor}` : '';
|
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Optional click handler
|
|
||||||
*/
|
|
||||||
function onClick(event) {
|
|
||||||
dispatch('click', event);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
|
||||||
{style}
|
|
||||||
on:click={onClick}>
|
|
||||||
{label}
|
|
||||||
</button>
|
|
|
@ -1,49 +0,0 @@
|
||||||
<script>
|
|
||||||
import './header.css';
|
|
||||||
import Button from './Button.svelte';
|
|
||||||
import Image from './Image.svelte';
|
|
||||||
import { hasSession } from '../utils/stores.js';
|
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
import { createEventDispatcher } from 'svelte';
|
|
||||||
|
|
||||||
let user = null;
|
|
||||||
onMount(async () => {
|
|
||||||
user = hasSession();
|
|
||||||
});
|
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
let avatarUrl = '';
|
|
||||||
|
|
||||||
function onLogin(event) {
|
|
||||||
dispatch('login', event);
|
|
||||||
}
|
|
||||||
function onLogout(event) {
|
|
||||||
dispatch('logout', event);
|
|
||||||
}
|
|
||||||
|
|
||||||
function redirect(url) {
|
|
||||||
return () => {
|
|
||||||
window.location.pathname = url;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<header>
|
|
||||||
<div class="wrapper">
|
|
||||||
<div>
|
|
||||||
<Image src="./clipboard.svg" on:click={redirect('/')} />
|
|
||||||
<h1>Todo</h1>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
{#if user}
|
|
||||||
<Image src={avatarUrl} alt="user profile picture" on:click={redirect('/settings')} />
|
|
||||||
<Button size="small" on:click={onLogout} label="Log out" />
|
|
||||||
{/if}
|
|
||||||
{#if !user}
|
|
||||||
<Button size="small" on:click={onLogin} label="Log in" />
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
|
@ -1,33 +0,0 @@
|
||||||
<script>
|
|
||||||
import './image.css';
|
|
||||||
import { createEventDispatcher } from 'svelte';
|
|
||||||
/**
|
|
||||||
* What background color to use
|
|
||||||
*/
|
|
||||||
export let backgroundColor;
|
|
||||||
|
|
||||||
export let size = 'small';
|
|
||||||
|
|
||||||
export let src = '';
|
|
||||||
export let alt = '';
|
|
||||||
|
|
||||||
let style = backgroundColor ? `background-color: ${backgroundColor}` : '';
|
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Optional click handler
|
|
||||||
*/
|
|
||||||
function onClick(event) {
|
|
||||||
dispatch('click', event);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<img
|
|
||||||
type="button"
|
|
||||||
class={['storybook-icon', `storybook-icon--${size}`].join(' ')}
|
|
||||||
{style}
|
|
||||||
on:click={onClick}
|
|
||||||
{src}
|
|
||||||
{alt}
|
|
||||||
/>
|
|
|
@ -1,60 +0,0 @@
|
||||||
<script>
|
|
||||||
export let segment;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
nav {
|
|
||||||
border-bottom: 1px solid rgba(255,62,0,0.1);
|
|
||||||
font-weight: 300;
|
|
||||||
padding: 0 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clearfix */
|
|
||||||
ul::after {
|
|
||||||
content: '';
|
|
||||||
display: block;
|
|
||||||
clear: both;
|
|
||||||
}
|
|
||||||
|
|
||||||
li {
|
|
||||||
display: block;
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
[aria-current] {
|
|
||||||
position: relative;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
[aria-current]::after {
|
|
||||||
position: absolute;
|
|
||||||
content: '';
|
|
||||||
width: calc(100% - 1em);
|
|
||||||
height: 2px;
|
|
||||||
background-color: rgb(255,62,0);
|
|
||||||
display: block;
|
|
||||||
bottom: -1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
text-decoration: none;
|
|
||||||
padding: 1em 0.5em;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<nav>
|
|
||||||
<ul>
|
|
||||||
<li><a aria-current="{segment === undefined ? 'page' : undefined}" href=".">home</a></li>
|
|
||||||
<li><a aria-current="{segment === 'about' ? 'page' : undefined}" href="about">about</a></li>
|
|
||||||
|
|
||||||
<!-- for the blog link, we're using rel=prefetch so that Sapper prefetches
|
|
||||||
the blog data when we hover over the link or tap it on a touchscreen -->
|
|
||||||
<li><a rel=prefetch aria-current="{segment === 'blog' ? 'page' : undefined}" href="blog">blog</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
|
@ -1,30 +0,0 @@
|
||||||
.storybook-button {
|
|
||||||
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
||||||
font-weight: 700;
|
|
||||||
border: 0;
|
|
||||||
border-radius: 3em;
|
|
||||||
cursor: pointer;
|
|
||||||
display: inline-block;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
.storybook-button--primary {
|
|
||||||
color: white;
|
|
||||||
background-color: #1ea7fd;
|
|
||||||
}
|
|
||||||
.storybook-button--secondary {
|
|
||||||
color: #333;
|
|
||||||
background-color: transparent;
|
|
||||||
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
|
|
||||||
}
|
|
||||||
.storybook-button--small {
|
|
||||||
font-size: 12px;
|
|
||||||
padding: 10px 16px;
|
|
||||||
}
|
|
||||||
.storybook-button--medium {
|
|
||||||
font-size: 14px;
|
|
||||||
padding: 11px 20px;
|
|
||||||
}
|
|
||||||
.storybook-button--large {
|
|
||||||
font-size: 16px;
|
|
||||||
padding: 12px 24px;
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
.wrapper {
|
|
||||||
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
||||||
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
|
||||||
padding: 15px 20px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
|
|
||||||
svg {
|
|
||||||
display: inline-block;
|
|
||||||
vertical-align: top;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-weight: 900;
|
|
||||||
font-size: 20px;
|
|
||||||
line-height: 1;
|
|
||||||
margin: 6px 0 6px 10px;
|
|
||||||
display: inline-block;
|
|
||||||
vertical-align: top;
|
|
||||||
}
|
|
||||||
|
|
||||||
button + button {
|
|
||||||
margin-left: 10px;
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
.storybook-icon {
|
|
||||||
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
||||||
font-weight: 700;
|
|
||||||
border: 0;
|
|
||||||
border-radius: 3em;
|
|
||||||
cursor: pointer;
|
|
||||||
display: inline-block;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.storybook-icon--small {
|
|
||||||
height: 32px;
|
|
||||||
width: auto;
|
|
||||||
}
|
|
||||||
.storybook-icon--medium {
|
|
||||||
height: 64px;
|
|
||||||
width: auto;
|
|
||||||
}
|
|
||||||
.storybook-icon--large {
|
|
||||||
height: 128px;
|
|
||||||
width: auto;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
import posts from './_posts.js';
|
|
||||||
|
|
||||||
const lookup = new Map();
|
|
||||||
posts.forEach(post => {
|
|
||||||
lookup.set(post.slug, JSON.stringify(post));
|
|
||||||
});
|
|
||||||
|
|
||||||
export function get(req, res, next) {
|
|
||||||
// the `slug` parameter is available because
|
|
||||||
// this file is called [slug].json.js
|
|
||||||
const { slug } = req.params;
|
|
||||||
|
|
||||||
if (lookup.has(slug)) {
|
|
||||||
res.writeHead(200, {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
});
|
|
||||||
|
|
||||||
res.end(lookup.get(slug));
|
|
||||||
} else {
|
|
||||||
res.writeHead(404, {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
});
|
|
||||||
|
|
||||||
res.end(JSON.stringify({
|
|
||||||
message: `Not found`
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
<script context="module">
|
|
||||||
export async function preload({ params }) {
|
|
||||||
// the `slug` parameter is available because
|
|
||||||
// this file is called [slug].svelte
|
|
||||||
const res = await this.fetch(`blog/${params.slug}.json`);
|
|
||||||
const data = await res.json();
|
|
||||||
|
|
||||||
if (res.status === 200) {
|
|
||||||
return { post: data };
|
|
||||||
} else {
|
|
||||||
this.error(res.status, data.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export let post;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
/*
|
|
||||||
By default, CSS is locally scoped to the component,
|
|
||||||
and any unused styles are dead-code-eliminated.
|
|
||||||
In this page, Svelte can't know which elements are
|
|
||||||
going to appear inside the {{{post.html}}} block,
|
|
||||||
so we have to use the :global(...) modifier to target
|
|
||||||
all elements inside .content
|
|
||||||
*/
|
|
||||||
.content :global(h2) {
|
|
||||||
font-size: 1.4em;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content :global(pre) {
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
box-shadow: inset 1px 1px 5px rgba(0, 0, 0, 0.05);
|
|
||||||
padding: 0.5em;
|
|
||||||
border-radius: 2px;
|
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content :global(pre) :global(code) {
|
|
||||||
background-color: transparent;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content :global(ul) {
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content :global(li) {
|
|
||||||
margin: 0 0 0.5em 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title>{post.title}</title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<h1>{post.title}</h1>
|
|
||||||
|
|
||||||
<div class="content">
|
|
||||||
{@html post.html}
|
|
||||||
</div>
|
|
|
@ -1,92 +0,0 @@
|
||||||
// Ordinarily, you'd generate this data from markdown files in your
|
|
||||||
// repo, or fetch them from a database of some kind. But in order to
|
|
||||||
// avoid unnecessary dependencies in the starter template, and in the
|
|
||||||
// service of obviousness, we're just going to leave it here.
|
|
||||||
|
|
||||||
// This file is called `_posts.js` rather than `posts.js`, because
|
|
||||||
// we don't want to create an `/blog/posts` route — the leading
|
|
||||||
// underscore tells Sapper not to do that.
|
|
||||||
|
|
||||||
const posts = [
|
|
||||||
{
|
|
||||||
title: 'What is Sapper?',
|
|
||||||
slug: 'what-is-sapper',
|
|
||||||
html: `
|
|
||||||
<p>First, you have to know what <a href='https://svelte.dev'>Svelte</a> is. Svelte is a UI framework with a bold new idea: rather than providing a library that you write code with (like React or Vue, for example), it's a compiler that turns your components into highly optimized vanilla JavaScript. If you haven't already read the <a href='https://svelte.dev/blog/frameworks-without-the-framework'>introductory blog post</a>, you should!</p>
|
|
||||||
|
|
||||||
<p>Sapper is a Next.js-style framework (<a href='blog/how-is-sapper-different-from-next'>more on that here</a>) built around Svelte. It makes it embarrassingly easy to create extremely high performance web apps. Out of the box, you get:</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li>Code-splitting, dynamic imports and hot module replacement, powered by webpack</li>
|
|
||||||
<li>Server-side rendering (SSR) with client-side hydration</li>
|
|
||||||
<li>Service worker for offline support, and all the PWA bells and whistles</li>
|
|
||||||
<li>The nicest development experience you've ever had, or your money back</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p>It's implemented as Express middleware. Everything is set up and waiting for you to get started, but you keep complete control over the server, service worker, webpack config and everything else, so it's as flexible as you need it to be.</p>
|
|
||||||
`
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
title: 'How to use Sapper',
|
|
||||||
slug: 'how-to-use-sapper',
|
|
||||||
html: `
|
|
||||||
<h2>Step one</h2>
|
|
||||||
<p>Create a new project, using <a href='https://github.com/Rich-Harris/degit'>degit</a>:</p>
|
|
||||||
|
|
||||||
<pre><code>npx degit "sveltejs/sapper-template#rollup" my-app
|
|
||||||
cd my-app
|
|
||||||
npm install # or yarn!
|
|
||||||
npm run dev
|
|
||||||
</code></pre>
|
|
||||||
|
|
||||||
<h2>Step two</h2>
|
|
||||||
<p>Go to <a href='http://localhost:3000'>localhost:3000</a>. Open <code>my-app</code> in your editor. Edit the files in the <code>src/routes</code> directory or add new ones.</p>
|
|
||||||
|
|
||||||
<h2>Step three</h2>
|
|
||||||
<p>...</p>
|
|
||||||
|
|
||||||
<h2>Step four</h2>
|
|
||||||
<p>Resist overdone joke formats.</p>
|
|
||||||
`
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
title: 'Why the name?',
|
|
||||||
slug: 'why-the-name',
|
|
||||||
html: `
|
|
||||||
<p>In war, the soldiers who build bridges, repair roads, clear minefields and conduct demolitions — all under combat conditions — are known as <em>sappers</em>.</p>
|
|
||||||
|
|
||||||
<p>For web developers, the stakes are generally lower than those for combat engineers. But we face our own hostile environment: underpowered devices, poor network connections, and the complexity inherent in front-end engineering. Sapper, which is short for <strong>S</strong>velte <strong>app</strong> mak<strong>er</strong>, is your courageous and dutiful ally.</p>
|
|
||||||
`
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
title: 'How is Sapper different from Next.js?',
|
|
||||||
slug: 'how-is-sapper-different-from-next',
|
|
||||||
html: `
|
|
||||||
<p><a href='https://github.com/zeit/next.js'>Next.js</a> is a React framework from <a href='https://vercel.com/'>Vercel</a>, and is the inspiration for Sapper. There are a few notable differences, however:</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li>It's powered by <a href='https://svelte.dev'>Svelte</a> instead of React, so it's faster and your apps are smaller</li>
|
|
||||||
<li>Instead of route masking, we encode route parameters in filenames. For example, the page you're looking at right now is <code>src/routes/blog/[slug].svelte</code></li>
|
|
||||||
<li>As well as pages (Svelte components, which render on server or client), you can create <em>server routes</em> in your <code>routes</code> directory. These are just <code>.js</code> files that export functions corresponding to HTTP methods, and receive Express <code>request</code> and <code>response</code> objects as arguments. This makes it very easy to, for example, add a JSON API such as the one <a href='blog/how-is-sapper-different-from-next.json'>powering this very page</a></li>
|
|
||||||
<li>Links are just <code><a></code> elements, rather than framework-specific <code><Link></code> components. That means, for example, that <a href='blog/how-can-i-get-involved'>this link right here</a>, despite being inside a blob of HTML, works with the router as you'd expect.</li>
|
|
||||||
</ul>
|
|
||||||
`
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
title: 'How can I get involved?',
|
|
||||||
slug: 'how-can-i-get-involved',
|
|
||||||
html: `
|
|
||||||
<p>We're so glad you asked! Come on over to the <a href='https://github.com/sveltejs/svelte'>Svelte</a> and <a href='https://github.com/sveltejs/sapper'>Sapper</a> repos, and join us in the <a href='https://svelte.dev/chat'>Discord chatroom</a>. Everyone is welcome, especially you!</p>
|
|
||||||
`
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
posts.forEach(post => {
|
|
||||||
post.html = post.html.replace(/^\t{3}/gm, '');
|
|
||||||
});
|
|
||||||
|
|
||||||
export default posts;
|
|
|
@ -1,16 +0,0 @@
|
||||||
import posts from './_posts.js';
|
|
||||||
|
|
||||||
const contents = JSON.stringify(posts.map(post => {
|
|
||||||
return {
|
|
||||||
title: post.title,
|
|
||||||
slug: post.slug
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
|
|
||||||
export function get(req, res) {
|
|
||||||
res.writeHead(200, {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
});
|
|
||||||
|
|
||||||
res.end(contents);
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
<script context="module">
|
|
||||||
export function preload() {
|
|
||||||
return this.fetch(`blog.json`).then(r => r.json()).then(posts => {
|
|
||||||
return { posts };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export let posts;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
ul {
|
|
||||||
margin: 0 0 1em 0;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title>Blog</title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<h1>Recent posts</h1>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
{#each posts as post}
|
|
||||||
<!-- we're using the non-standard `rel=prefetch` attribute to
|
|
||||||
tell Sapper to load the data for the page as soon as
|
|
||||||
the user hovers over the link or taps it, instead of
|
|
||||||
waiting for the 'click' event -->
|
|
||||||
<li><a rel="prefetch" href="blog/{post.slug}">{post.title}</a></li>
|
|
||||||
{/each}
|
|
||||||
</ul>
|
|
|
@ -1,40 +0,0 @@
|
||||||
<script>
|
|
||||||
export let status;
|
|
||||||
export let error;
|
|
||||||
|
|
||||||
const dev = process.env.NODE_ENV === 'development';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
h1, p {
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 2.8em;
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 0.5em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
margin: 1em auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 480px) {
|
|
||||||
h1 {
|
|
||||||
font-size: 4em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title>{status}</title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<h1>{status}</h1>
|
|
||||||
|
|
||||||
<p>{error.message}</p>
|
|
||||||
|
|
||||||
{#if dev && error.stack}
|
|
||||||
<pre>{error.stack}</pre>
|
|
||||||
{/if}
|
|
|
@ -1,24 +0,0 @@
|
||||||
<script>
|
|
||||||
// import Nav from '../components/Nav.svelte';
|
|
||||||
|
|
||||||
// export let segment;
|
|
||||||
import Header from '../components/Header.svelte';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
main {
|
|
||||||
position: relative;
|
|
||||||
max-width: 56em;
|
|
||||||
background-color: white;
|
|
||||||
padding: 2em;
|
|
||||||
margin: 0 auto;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<!-- <Nav {segment}/> -->
|
|
||||||
<Header />
|
|
||||||
|
|
||||||
<main>
|
|
||||||
<slot></slot>
|
|
||||||
</main>
|
|
|
@ -1,7 +0,0 @@
|
||||||
<svelte:head>
|
|
||||||
<title>About</title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<h1>About this site</h1>
|
|
||||||
|
|
||||||
<p>This is the 'about' page. There's not much here.</p>
|
|
|
@ -1,9 +0,0 @@
|
||||||
<script>
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svelte:head>
|
|
||||||
<title>Todo</title>
|
|
||||||
</svelte:head>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
</style>
|
|
|
@ -1,17 +0,0 @@
|
||||||
import sirv from 'sirv';
|
|
||||||
import polka from 'polka';
|
|
||||||
import compression from 'compression';
|
|
||||||
import * as sapper from '@sapper/server';
|
|
||||||
|
|
||||||
const { PORT, NODE_ENV } = process.env;
|
|
||||||
const dev = NODE_ENV === 'development';
|
|
||||||
|
|
||||||
polka() // You can also use Express
|
|
||||||
.use(
|
|
||||||
compression({ threshold: 0 }),
|
|
||||||
sirv('static', { dev }),
|
|
||||||
sapper.middleware()
|
|
||||||
)
|
|
||||||
.listen(PORT, err => {
|
|
||||||
if (err) console.log('error', err);
|
|
||||||
});
|
|
|
@ -1,86 +0,0 @@
|
||||||
import { timestamp, files, shell } from '@sapper/service-worker';
|
|
||||||
|
|
||||||
const ASSETS = `cache${timestamp}`;
|
|
||||||
|
|
||||||
// `shell` is an array of all the files generated by the bundler,
|
|
||||||
// `files` is an array of everything in the `static` directory
|
|
||||||
const to_cache = shell.concat(files);
|
|
||||||
const staticAssets = new Set(to_cache);
|
|
||||||
|
|
||||||
self.addEventListener('install', event => {
|
|
||||||
event.waitUntil(
|
|
||||||
caches
|
|
||||||
.open(ASSETS)
|
|
||||||
.then(cache => cache.addAll(to_cache))
|
|
||||||
.then(() => {
|
|
||||||
self.skipWaiting();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener('activate', event => {
|
|
||||||
event.waitUntil(
|
|
||||||
caches.keys().then(async keys => {
|
|
||||||
// delete old caches
|
|
||||||
for (const key of keys) {
|
|
||||||
if (key !== ASSETS) await caches.delete(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.clients.claim();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch the asset from the network and store it in the cache.
|
|
||||||
* Fall back to the cache if the user is offline.
|
|
||||||
*/
|
|
||||||
async function fetchAndCache(request) {
|
|
||||||
const cache = await caches.open(`offline${timestamp}`)
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(request);
|
|
||||||
cache.put(request, response.clone());
|
|
||||||
return response;
|
|
||||||
} catch (err) {
|
|
||||||
const response = await cache.match(request);
|
|
||||||
if (response) return response;
|
|
||||||
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.addEventListener('fetch', event => {
|
|
||||||
if (event.request.method !== 'GET' || event.request.headers.has('range')) return;
|
|
||||||
|
|
||||||
const url = new URL(event.request.url);
|
|
||||||
|
|
||||||
// don't try to handle e.g. data: URIs
|
|
||||||
const isHttp = url.protocol.startsWith('http');
|
|
||||||
const isDevServerRequest = url.hostname === self.location.hostname && url.port !== self.location.port;
|
|
||||||
const isStaticAsset = url.host === self.location.host && staticAssets.has(url.pathname);
|
|
||||||
const skipBecauseUncached = event.request.cache === 'only-if-cached' && !isStaticAsset;
|
|
||||||
|
|
||||||
if (isHttp && !isDevServerRequest && !skipBecauseUncached) {
|
|
||||||
event.respondWith(
|
|
||||||
(async () => {
|
|
||||||
// always serve static files and bundler-generated assets from cache.
|
|
||||||
// if your application has other URLs with data that will never change,
|
|
||||||
// set this variable to true for them and they will only be fetched once.
|
|
||||||
const cachedAsset = isStaticAsset && await caches.match(event.request);
|
|
||||||
|
|
||||||
// for pages, you might want to serve a shell `service-worker-index.html` file,
|
|
||||||
// which Sapper has generated for you. It's not right for every
|
|
||||||
// app, but if it's right for yours then uncomment this section
|
|
||||||
/*
|
|
||||||
if (!cachedAsset && url.origin === self.origin && routes.find(route => route.pattern.test(url.pathname))) {
|
|
||||||
return caches.match('/service-worker-index.html');
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return cachedAsset || fetchAndCache(event.request);
|
|
||||||
})()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -1,34 +0,0 @@
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
||||||
<meta name="theme-color" content="#333333">
|
|
||||||
|
|
||||||
%sapper.base%
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="global.css">
|
|
||||||
<link rel="manifest" href="manifest.json" crossorigin="use-credentials">
|
|
||||||
<link rel="icon" type="image/png" href="favicon.png">
|
|
||||||
<link rel="apple-touch-icon" href="logo-192.png">
|
|
||||||
|
|
||||||
<!-- Sapper creates a <script> tag containing `src/client.js`
|
|
||||||
and anything else it needs to hydrate the app and
|
|
||||||
initialise the router -->
|
|
||||||
%sapper.scripts%
|
|
||||||
|
|
||||||
<!-- Sapper generates a <style> tag containing critical CSS
|
|
||||||
for the current page. CSS for the rest of the app is
|
|
||||||
lazily loaded when it precaches secondary pages -->
|
|
||||||
%sapper.styles%
|
|
||||||
|
|
||||||
<!-- This contains the contents of the <svelte:head> component, if
|
|
||||||
the current page has one -->
|
|
||||||
%sapper.head%
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<!-- The application will be rendered inside this element,
|
|
||||||
because `src/client.js` references it -->
|
|
||||||
<div id="sapper">%sapper.html%</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1 +0,0 @@
|
||||||
export const API_URL = 'https://dev.j4.pm/api';
|
|
|
@ -1,31 +0,0 @@
|
||||||
import { writable } from 'svelte/store';
|
|
||||||
import axios from 'axios';
|
|
||||||
import { API_URL } from './settings';
|
|
||||||
|
|
||||||
export const discordUser = writable({});
|
|
||||||
|
|
||||||
export const hasSession = () => {
|
|
||||||
return getCookie('SESSION') != null;
|
|
||||||
};
|
|
||||||
|
|
||||||
function getCookie(name) {
|
|
||||||
if (!window.document) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var dc = window.document.cookie;
|
|
||||||
var prefix = name + '=';
|
|
||||||
var begin = dc.indexOf('; ' + prefix);
|
|
||||||
if (begin == -1) {
|
|
||||||
begin = dc.indexOf(prefix);
|
|
||||||
if (begin != 0) return null;
|
|
||||||
} else {
|
|
||||||
begin += 2;
|
|
||||||
var end = window.document.cookie.indexOf(';', begin);
|
|
||||||
if (end == -1) {
|
|
||||||
end = dc.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// because unescape has been deprecated, replaced with decodeURI
|
|
||||||
//return unescape(dc.substring(begin + prefix.length, end));
|
|
||||||
return decodeURI(dc.substring(begin + prefix.length, end));
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="48px" viewBox="0 0 24 24" width="48px" fill="#000000"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 3h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm2 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z"/></svg>
|
|
Before Width: | Height: | Size: 379 B |
|
@ -1 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" version="1.1" viewBox="0 0 48 48"><title>illustration/code-brackets</title><g id="illustration/code-brackets" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><path id="Combined-Shape" fill="#87E6E5" d="M11.4139325,12 C11.7605938,12 12,12.5059743 12,13.3779712 L12,17.4951758 L6.43502246,23.3839989 C5.85499251,23.9978337 5.85499251,25.0021663 6.43502246,25.6160011 L12,31.5048242 L12,35.6220288 C12,36.4939606 11.7605228,37 11.4139325,37 C11.2725831,37 11.1134406,36.9158987 10.9453839,36.7379973 L0.435022463,25.6160011 C-0.145007488,25.0021663 -0.145007488,23.9978337 0.435022463,23.3839989 L10.9453839,12.2620027 C11.1134051,12.0841663 11.2725831,12 11.4139325,12 Z M36.5860675,12 C36.7274169,12 36.8865594,12.0841013 37.0546161,12.2620027 L47.5649775,23.3839989 C48.1450075,23.9978337 48.1450075,25.0021663 47.5649775,25.6160011 L37.0546161,36.7379973 C36.8865949,36.9158337 36.7274169,37 36.5860675,37 C36.2394062,37 36,36.4940257 36,35.6220288 L36,31.5048242 L41.5649775,25.6160011 C42.1450075,25.0021663 42.1450075,23.9978337 41.5649775,23.3839989 L36,17.4951758 L36,13.3779712 C36,12.5060394 36.2394772,12 36.5860675,12 Z"/><rect id="Rectangle-7-Copy-5" width="35.57" height="4" x="5.009" y="22.662" fill="#A0DB77" rx="2" transform="translate(22.793959, 24.662305) rotate(-75.000000) translate(-22.793959, -24.662305)"/></g></svg>
|
|
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 8.3 KiB |
|
@ -1 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" version="1.1" viewBox="0 0 48 48"><title>illustration/comments</title><g id="illustration/comments" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><path id="Path" fill="#96D07C" d="M2.52730803,17.9196415 C2.44329744,17.9745167 2.36370847,18.000488 2.29303375,18.000488 C2.1197031,18.000488 2,17.8443588 2,17.5752855 L2,4 C2,1.790861 3.790861,3.23296945e-13 6,3.23296945e-13 L33.9995117,3.23296945e-13 C36.2086507,3.23296945e-13 37.9995117,1.790861 37.9995117,4 L37.9995117,9.999512 C37.9995117,12.208651 36.2086507,13.999512 33.9995117,13.999512 L8,13.999512 C7.83499225,13.999512 7.6723181,13.9895206 7.51254954,13.9701099 L2.52730803,17.9196415 Z"/><path id="Path" fill="#73E1E0" d="M7.51066,44.9703679 L2.52730803,47.9186655 C2.44329744,47.9735407 2.36370847,47.999512 2.29303375,47.999512 C2.1197031,47.999512 2,47.8433828 2,47.5743095 L2,35 C2,32.790861 3.790861,31 6,31 L26,31 C28.209139,31 30,32.790861 30,35 L30,41 C30,43.209139 28.209139,45 26,45 L8,45 C7.8343417,45 7.67103544,44.9899297 7.51066,44.9703679 Z"/><path id="Path" fill="#FFD476" d="M46,19.5 L46,33.0747975 C46,33.3438708 45.8802969,33.5 45.7069663,33.5 C45.6362915,33.5 45.5567026,33.4740287 45.472692,33.4191535 L40.4887103,29.4704446 C40.3285371,29.489956 40.1654415,29.5 40,29.5 L18,29.5 C15.790861,29.5 14,27.709139 14,25.5 L14,19.5 C14,17.290861 15.790861,15.5 18,15.5 L42,15.5 C44.209139,15.5 46,17.290861 46,19.5 Z"/></g></svg>
|
|
Before Width: | Height: | Size: 1.5 KiB |
|
@ -1 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" version="1.1" viewBox="0 0 48 48"><title>illustration/direction</title><g id="illustration/direction" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><path id="Combined-Shape" fill="#FFD476" d="M23.4917015,33.6030641 L2.93840258,31.4321033 C2.38917316,31.3740904 1.99096346,30.8818233 2.04897631,30.3325939 C2.0747515,30.0885705 2.18934861,29.8625419 2.37095722,29.6975265 L34.2609105,0.721285325 C34.6696614,0.349881049 35.3021022,0.38015648 35.6735064,0.788907393 C35.9232621,1.06377731 36.0001133,1.45442096 35.8730901,1.80341447 L24.5364357,32.9506164 C24.3793473,33.3822133 23.9484565,33.6513092 23.4917015,33.6030641 L23.4917015,33.6030641 Z"/><path id="Combined-Shape-Copy" fill="#FFC445" d="M24.3163597,33.2881029 C24.0306575,33.0138462 23.9337246,32.5968232 24.069176,32.2246735 L35.091923,1.9399251 C35.2266075,1.56988243 35.5659249,1.31333613 35.9586669,1.28460955 C36.5094802,1.24432106 36.9886628,1.65818318 37.0289513,2.20899647 L40.2437557,46.1609256 C40.2644355,46.4436546 40.1641446,46.7218752 39.9678293,46.9263833 C39.5853672,47.3248067 38.9523344,47.3377458 38.5539111,46.9552837 L24.3163597,33.2881029 L24.3163597,33.2881029 Z"/></g></svg>
|
|
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 3.1 KiB |
|
@ -1 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" version="1.1" viewBox="0 0 48 48"><title>illustration/flow</title><g id="illustration/flow" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><path id="Combined-Shape" fill="#79C9FC" fill-rule="nonzero" d="M30,29 C32.7614237,29 35,26.7614237 35,24 C35,14.6111593 27.3888407,7 18,7 C8.61115925,7 1,14.6111593 1,24 C1,33.3888407 8.61115925,41 18,41 C19.3333404,41 20.6447683,40.8466238 21.9154603,40.5471706 C19.5096374,39.3319645 17.5510566,37.8612875 16.0456579,36.1314815 C14.1063138,33.9030427 12.769443,31.0725999 12.0293806,27.6556449 C11.360469,26.565281 11,25.3082308 11,24 C11,20.1340068 14.1340068,17 18,17 C21.8659932,17 25,20.1340068 25,24 C25,26.125 27.7040312,29 30,29 Z"/><path id="Combined-Shape-Copy" fill="#FFC445" fill-rule="nonzero" d="M42,29 C44.7614237,29 47,26.7614237 47,24 C47,14.6111593 39.3888407,7 30,7 C20.6111593,7 13,14.6111593 13,24 C13,33.3888407 20.6111593,41 30,41 C31.3333404,41 32.6447683,40.8466238 33.9154603,40.5471706 C31.5096374,39.3319645 29.4051056,37.9781963 28.0456579,36.1314815 C26.0625,33.4375 23,27.1875 23,24 C23,20.1340068 26.1340068,17 30,17 C33.8659932,17 37,20.1340068 37,24 C37.02301,26.3435241 39.7040312,29 42,29 Z" transform="translate(30.000000, 24.000000) scale(-1, -1) translate(-30.000000, -24.000000)"/></g></svg>
|
|
Before Width: | Height: | Size: 1.4 KiB |
|
@ -1,36 +0,0 @@
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: Roboto, -apple-system, BlinkMacSystemFont, Segoe UI, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.5;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1, h2, h3, h4, h5, h6 {
|
|
||||||
margin: 0 0 0.5em 0;
|
|
||||||
font-weight: 400;
|
|
||||||
line-height: 1.2;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
font-size: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
code {
|
|
||||||
font-family: menlo, inconsolata, monospace;
|
|
||||||
font-size: calc(1em - 2px);
|
|
||||||
color: #555;
|
|
||||||
background-color: #f0f0f0;
|
|
||||||
padding: 0.2em 0.4em;
|
|
||||||
border-radius: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: 400px) {
|
|
||||||
body {
|
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
}
|
|
Before Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 14 KiB |
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"background_color": "#ffffff",
|
|
||||||
"theme_color": "#333333",
|
|
||||||
"name": "TODO",
|
|
||||||
"short_name": "TODO",
|
|
||||||
"display": "minimal-ui",
|
|
||||||
"start_url": "/",
|
|
||||||
"icons": [
|
|
||||||
{
|
|
||||||
"src": "logo-192.png",
|
|
||||||
"sizes": "192x192",
|
|
||||||
"type": "image/png",
|
|
||||||
"purpose": "any maskable"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "logo-512.png",
|
|
||||||
"sizes": "512x512",
|
|
||||||
"type": "image/png",
|
|
||||||
"purpose": "any maskable"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" version="1.1" viewBox="0 0 48 48"><title>illustration/plugin</title><g id="illustration/plugin" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><path id="Combined-Shape" fill="#79C9FC" d="M26,15.3994248 C26,15.4091303 26,15.4188459 26,15.4285714 L26,21.4694881 C25.8463595,21.4969567 25.6941676,21.51275 25.5873784,21.51275 C25.4974117,21.51275 25.4230979,21.4768034 25.377756,21.4206259 L25.2660784,21.2822603 L25.1317423,21.1657666 C24.2436317,20.3956144 23.100098,19.9633214 21.895551,19.9633214 C19.2039137,19.9633214 17,22.1075558 17,24.7804643 C17,27.4533728 19.2039137,29.5976071 21.895551,29.5976071 C23.1972122,29.5976071 24.3149423,29.2878193 25.1231445,28.3613697 C25.4542273,27.9818463 25.568273,27.9073214 25.5873784,27.9073214 C25.681532,27.9073214 25.8352452,27.9239643 26,27.9524591 L26,32.5714286 C26,32.5811541 26,32.5908697 26,32.6005752 L26,33 C26,35.209139 24.209139,37 22,37 L4,37 C1.790861,37 0,35.209139 0,33 L0,15 C0,12.790861 1.790861,11 4,11 L22,11 C24.209139,11 26,12.790861 26,15 L26,15.3994248 Z"/><path id="Path" fill="#87E6E5" d="M27.9998779,32.5714286 C27.9998779,33.3604068 28.6572726,34 29.4682101,34 L46.5315458,34 C47.3424832,34 47.9998779,33.3604068 47.9998779,32.5714286 L47.9998779,15.4285714 C47.9998779,14.6395932 47.3424832,14 46.5315458,14 L29.4682101,14 C28.6572726,14 27.9998779,14.6395932 27.9998779,15.4285714 L27.9998779,21.8355216 C27.9334367,22.2650514 27.8567585,22.6454496 27.746391,22.8084643 C27.4245309,23.2838571 26.2402709,23.51275 25.5873784,23.51275 C24.8705773,23.51275 24.2322714,23.1857725 23.8214379,22.6767605 C23.3096996,22.2329909 22.6349941,21.9633214 21.895551,21.9633214 C20.2963823,21.9633214 19,23.2245992 19,24.7804643 C19,26.3363293 20.2963823,27.5976071 21.895551,27.5976071 C22.5398535,27.5976071 23.2399343,27.477727 23.6160247,27.0466112 C24.1396029,26.4464286 24.7367044,25.9073214 25.5873784,25.9073214 C26.2402709,25.9073214 27.5912951,26.1766031 27.8226692,26.6116071 C27.8819199,26.7230038 27.9403239,26.921677 27.9998779,27.1556219 L27.9998779,32.5714286 Z"/></g></svg>
|
|
Before Width: | Height: | Size: 2.1 KiB |
|
@ -1 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" version="1.1" viewBox="0 0 48 48"><title>illustration/repo</title><g id="illustration/repo" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><path id="Rectangle-62-Copy" fill="#B7F0EF" d="M27.2217723,9.04506931 L41.2217723,6.2682098 C43.3886973,5.83840648 45.4937616,7.2466219 45.9235649,9.41354696 C45.9743993,9.66983721 46,9.93049166 46,10.1917747 L46,32.581381 C46,34.4904961 44.650862,36.1335143 42.7782277,36.5049459 L28.7782277,39.2818054 C26.6113027,39.7116087 24.5062384,38.3033933 24.0764351,36.1364682 C24.0256007,35.880178 24,35.6195235 24,35.3582405 L24,12.9686342 C24,11.0595191 25.349138,9.4165009 27.2217723,9.04506931 Z" opacity=".7"/><path id="Combined-Shape" fill="#87E6E5" d="M6.77822775,6.2682098 L20.7782277,9.04506931 C22.650862,9.4165009 24,11.0595191 24,12.9686342 L24,35.3582405 C24,37.5673795 22.209139,39.3582405 20,39.3582405 C19.738717,39.3582405 19.4780625,39.3326398 19.2217723,39.2818054 L5.22177225,36.5049459 C3.34913798,36.1335143 2,34.4904961 2,32.581381 L2,10.1917747 C2,7.98263571 3.790861,6.19177471 6,6.19177471 C6.26128305,6.19177471 6.5219375,6.21737537 6.77822775,6.2682098 Z"/><path id="Rectangle-63-Copy-2" fill="#61C1FD" d="M22,10 C23.1666667,10.2291667 24.0179036,10.625 24.5537109,11.1875 C25.0895182,11.75 25.5716146,12.875 26,14.5625 C26,29.3020833 26,37.5208333 26,39.21875 C26,40.9166667 26.4241536,42.9583333 27.2724609,45.34375 L24.5537109,41.875 L22.9824219,45.34375 C22.327474,43.1979167 22,41.2291667 22,39.4375 C22,37.6458333 22,27.8333333 22,10 Z"/></g></svg>
|
|
Before Width: | Height: | Size: 1.6 KiB |
|
@ -1 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48" version="1.1" viewBox="0 0 48 48"><title>illustration/stackalt</title><g id="illustration/stackalt" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><path id="Combined-Shape" fill="#FFAE00" d="M23.8628277,0 L23.8628277,48 L3.32291648,36.2491883 L3.32155653,11.9499781 L23.8628277,0 Z M23.8670509,0 L44.408322,11.9499781 L44.4069621,36.2491883 L23.8670509,48 L23.8670509,0 Z" opacity=".196"/><path id="Rectangle-46-Copy-3" fill="#66BF3C" d="M15.8232279,19.1155258 L24.7368455,21.4714881 C29.6053842,22.7582937 33.4077423,26.5606518 34.694548,31.4291905 L37.0505103,40.3428082 C37.6150232,42.4786032 36.3412474,44.6676353 34.2054524,45.2321482 C33.5569474,45.4035549 32.87575,45.4091235 32.2245294,45.2483418 L23.3459013,43.0562718 C18.2976962,41.809906 14.3561301,37.8683399 13.1097642,32.8201348 L10.9176943,23.9415066 C10.3881737,21.7967682 11.6975664,19.6288529 13.8423049,19.0993322 C14.4935255,18.9385505 15.1747229,18.9441191 15.8232279,19.1155258 Z" opacity=".5" transform="translate(23.999997, 32.166058) rotate(-45.000000) translate(-23.999997, -32.166058)"/><path id="Rectangle-46-Copy-2" fill="#FFAE00" d="M15.8232279,11.2216893 L24.7368455,13.5776516 C29.6053842,14.8644572 33.4077423,18.6668153 34.694548,23.5353541 L37.0505103,32.4489717 C37.6150232,34.5847667 36.3412474,36.7737988 34.2054524,37.3383117 C33.5569474,37.5097184 32.87575,37.515287 32.2245294,37.3545053 L23.3459013,35.1624353 C18.2976962,33.9160695 14.3561301,29.9745034 13.1097642,24.9262983 L10.9176943,16.0476701 C10.3881737,13.9029317 11.6975664,11.7350164 13.8423049,11.2054957 C14.4935255,11.044714 15.1747229,11.0502826 15.8232279,11.2216893 Z" opacity=".5" transform="translate(23.999997, 24.272222) rotate(-45.000000) translate(-23.999997, -24.272222)"/><path id="Rectangle-46-Copy" fill="#FC521F" d="M15.8232279,3.32785281 L24.7368455,5.68381509 C29.6053842,6.97062075 33.4077423,10.7729788 34.694548,15.6415176 L37.0505103,24.5551352 C37.6150232,26.6909302 36.3412474,28.8799623 34.2054524,29.4444752 C33.5569474,29.6158819 32.87575,29.6214505 32.2245294,29.4606688 L23.3459013,27.2685988 C18.2976962,26.022233 14.3561301,22.0806669 13.1097642,17.0324618 L10.9176943,8.15383364 C10.3881737,6.00909519 11.6975664,3.84117987 13.8423049,3.31165925 C14.4935255,3.15087753 15.1747229,3.15644615 15.8232279,3.32785281 Z" opacity=".5" transform="translate(23.999997, 16.378385) rotate(-45.000000) translate(-23.999997, -16.378385)"/></g></svg>
|
|
Before Width: | Height: | Size: 2.5 KiB |
15
src/endpoints.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
use axum::{prelude::*, routing::BoxRoute};
|
||||||
|
|
||||||
|
pub mod block;
|
||||||
|
pub mod discord;
|
||||||
|
pub mod user;
|
||||||
|
|
||||||
|
async fn hello() -> &'static str {
|
||||||
|
"Hi"
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_routes() -> BoxRoute<Body> {
|
||||||
|
route("/api/hello", any(hello))
|
||||||
|
.nest("/api/auth", discord::get_routes())
|
||||||
|
.boxed()
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ use std::env;
|
||||||
|
|
||||||
static COOKIE_NAME: &str = "SESSION";
|
static COOKIE_NAME: &str = "SESSION";
|
||||||
|
|
||||||
fn oauth_client() -> BasicClient {
|
pub fn oauth_client() -> BasicClient {
|
||||||
// Environment variables (* = required):
|
// Environment variables (* = required):
|
||||||
// *"CLIENT_ID" "123456789123456789";
|
// *"CLIENT_ID" "123456789123456789";
|
||||||
// *"CLIENT_SECRET" "rAn60Mch4ra-CTErsSf-r04utHcLienT";
|
// *"CLIENT_SECRET" "rAn60Mch4ra-CTErsSf-r04utHcLienT";
|
||||||
|
@ -39,13 +39,15 @@ fn oauth_client() -> BasicClient {
|
||||||
let token_url = env::var("TOKEN_URL")
|
let token_url = env::var("TOKEN_URL")
|
||||||
.unwrap_or_else(|_| "https://discord.com/api/oauth2/token".to_string());
|
.unwrap_or_else(|_| "https://discord.com/api/oauth2/token".to_string());
|
||||||
|
|
||||||
BasicClient::new(
|
let client = BasicClient::new(
|
||||||
ClientId::new(client_id),
|
ClientId::new(client_id),
|
||||||
Some(ClientSecret::new(client_secret)),
|
Some(ClientSecret::new(client_secret)),
|
||||||
AuthUrl::new(auth_url).unwrap(),
|
AuthUrl::new(auth_url).unwrap(),
|
||||||
Some(TokenUrl::new(token_url).unwrap()),
|
Some(TokenUrl::new(token_url).unwrap()),
|
||||||
)
|
)
|
||||||
.set_redirect_uri(RedirectUrl::new(redirect_url).unwrap())
|
.set_redirect_uri(RedirectUrl::new(redirect_url).unwrap());
|
||||||
|
tracing::debug!("client: {:?}", client);
|
||||||
|
client
|
||||||
}
|
}
|
||||||
|
|
||||||
// The user data we'll get back from Discord.
|
// The user data we'll get back from Discord.
|
||||||
|
@ -81,10 +83,15 @@ async fn discord_auth(Extension(client): Extension<BasicClient>) -> impl IntoRes
|
||||||
|
|
||||||
// Valid user session required. If there is none, redirect to the auth page
|
// Valid user session required. If there is none, redirect to the auth page
|
||||||
async fn protected(user: DiscordUser) -> impl IntoResponse {
|
async fn protected(user: DiscordUser) -> impl IntoResponse {
|
||||||
format!(
|
serde_json::to_string(&user).expect("could not serialize user")
|
||||||
"Welcome to the protected area :)\nHere's your info:\n{:?}",
|
}
|
||||||
user
|
|
||||||
)
|
async fn avatar_url(user: DiscordUser) -> impl IntoResponse {
|
||||||
|
let cdn_url = env::var("CDN_URL").unwrap_or_else(|_| "https://cdn.discordapp.com".to_string());
|
||||||
|
match user.avatar {
|
||||||
|
Some(id) => format!("{}/avatars/{}/{}.webp?size=256", cdn_url, user.id, id),
|
||||||
|
None => format!("{}/embed/avatars/0.png?size=256", cdn_url),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn logout(
|
async fn logout(
|
||||||
|
@ -205,10 +212,11 @@ where
|
||||||
|
|
||||||
pub fn get_routes() -> BoxRoute<Body> {
|
pub fn get_routes() -> BoxRoute<Body> {
|
||||||
route("/", get(index))
|
route("/", get(index))
|
||||||
.route("/login/discord", get(discord_auth))
|
.route("/discord", get(discord_auth))
|
||||||
.route("/authorized", get(login_authorized))
|
.route("/authorized", get(login_authorized))
|
||||||
.route("/protected", get(protected))
|
.route("/protected", get(protected))
|
||||||
|
.route("/avatar", get(avatar_url))
|
||||||
.route("/logout", get(logout))
|
.route("/logout", get(logout))
|
||||||
.layer(AddExtensionLayer::new(oauth_client))
|
.layer(AddExtensionLayer::new(oauth_client()))
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
|
@ -1,13 +1,14 @@
|
||||||
use crate::diesel::{prelude::*, PgConnection, QueryDsl};
|
use crate::diesel::{prelude::*, QueryDsl};
|
||||||
use crate::models::*;
|
use crate::models::*;
|
||||||
use crate::schema::*;
|
use crate::schema::*;
|
||||||
use diesel::r2d2::{ConnectionManager, Pool};
|
use diesel::r2d2::{ConnectionManager, Pool};
|
||||||
|
use diesel_tracing::pg::InstrumentedPgConnection;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use tokio_diesel::*;
|
use tokio_diesel::*;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub async fn create_block(
|
pub async fn create_block(
|
||||||
pool: &Pool<ConnectionManager<PgConnection>>,
|
pool: &Pool<ConnectionManager<InstrumentedPgConnection>>,
|
||||||
block: InsertableBlock,
|
block: InsertableBlock,
|
||||||
) -> Result<Block, Box<dyn Error>> {
|
) -> Result<Block, Box<dyn Error>> {
|
||||||
let inserted: Block = diesel::insert_into(blocks::table)
|
let inserted: Block = diesel::insert_into(blocks::table)
|
||||||
|
@ -18,7 +19,7 @@ pub async fn create_block(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_block(
|
pub async fn update_block(
|
||||||
pool: &Pool<ConnectionManager<PgConnection>>,
|
pool: &Pool<ConnectionManager<InstrumentedPgConnection>>,
|
||||||
block: Block,
|
block: Block,
|
||||||
) -> Result<Block, Box<dyn Error>> {
|
) -> Result<Block, Box<dyn Error>> {
|
||||||
use crate::schema::blocks::dsl::*;
|
use crate::schema::blocks::dsl::*;
|
||||||
|
@ -35,7 +36,7 @@ pub async fn update_block(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_block_by_id(
|
pub async fn find_block_by_id(
|
||||||
pool: &Pool<ConnectionManager<PgConnection>>,
|
pool: &Pool<ConnectionManager<InstrumentedPgConnection>>,
|
||||||
block_id: Uuid,
|
block_id: Uuid,
|
||||||
) -> Result<Block, Box<dyn Error>> {
|
) -> Result<Block, Box<dyn Error>> {
|
||||||
use crate::schema::blocks::dsl::*;
|
use crate::schema::blocks::dsl::*;
|
||||||
|
@ -45,7 +46,7 @@ pub async fn find_block_by_id(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_block_by_id(
|
pub async fn delete_block_by_id(
|
||||||
pool: &Pool<ConnectionManager<PgConnection>>,
|
pool: &Pool<ConnectionManager<InstrumentedPgConnection>>,
|
||||||
block_id: Uuid,
|
block_id: Uuid,
|
||||||
) -> Result<Block, Box<dyn Error>> {
|
) -> Result<Block, Box<dyn Error>> {
|
||||||
use crate::schema::blocks::dsl::*;
|
use crate::schema::blocks::dsl::*;
|
|
@ -1,13 +1,14 @@
|
||||||
use crate::diesel::{prelude::*, PgConnection, QueryDsl};
|
use crate::diesel::{prelude::*, QueryDsl};
|
||||||
use crate::models::*;
|
use crate::models::*;
|
||||||
use crate::schema::*;
|
use crate::schema::*;
|
||||||
use diesel::r2d2::{ConnectionManager, Pool};
|
use diesel::r2d2::{ConnectionManager, Pool};
|
||||||
|
use diesel_tracing::pg::InstrumentedPgConnection;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use tokio_diesel::*;
|
use tokio_diesel::*;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub async fn create_user(
|
pub async fn create_user(
|
||||||
pool: &Pool<ConnectionManager<PgConnection>>,
|
pool: &Pool<ConnectionManager<InstrumentedPgConnection>>,
|
||||||
user: InsertableUser,
|
user: InsertableUser,
|
||||||
) -> Result<User, Box<dyn Error>> {
|
) -> Result<User, Box<dyn Error>> {
|
||||||
let inserted: User = diesel::insert_into(users::table)
|
let inserted: User = diesel::insert_into(users::table)
|
||||||
|
@ -18,7 +19,7 @@ pub async fn create_user(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_user(
|
pub async fn update_user(
|
||||||
pool: &Pool<ConnectionManager<PgConnection>>,
|
pool: &Pool<ConnectionManager<InstrumentedPgConnection>>,
|
||||||
user: User,
|
user: User,
|
||||||
) -> Result<User, Box<dyn Error>> {
|
) -> Result<User, Box<dyn Error>> {
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
||||||
|
@ -30,7 +31,7 @@ pub async fn update_user(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_user_by_id(
|
pub async fn find_user_by_id(
|
||||||
pool: &Pool<ConnectionManager<PgConnection>>,
|
pool: &Pool<ConnectionManager<InstrumentedPgConnection>>,
|
||||||
user_id: Uuid,
|
user_id: Uuid,
|
||||||
) -> Result<User, Box<dyn Error>> {
|
) -> Result<User, Box<dyn Error>> {
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
||||||
|
@ -40,7 +41,7 @@ pub async fn find_user_by_id(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_user_by_id(
|
pub async fn delete_user_by_id(
|
||||||
pool: &Pool<ConnectionManager<PgConnection>>,
|
pool: &Pool<ConnectionManager<InstrumentedPgConnection>>,
|
||||||
user_id: Uuid,
|
user_id: Uuid,
|
||||||
) -> Result<User, Box<dyn Error>> {
|
) -> Result<User, Box<dyn Error>> {
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
88
src/main.rs
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
use axum::prelude::*;
|
||||||
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
|
|
||||||
|
use async_redis_session::RedisSessionStore;
|
||||||
|
use axum::AddExtensionLayer;
|
||||||
|
use diesel::r2d2::{ConnectionManager, Pool};
|
||||||
|
use diesel_tracing::pg::InstrumentedPgConnection;
|
||||||
|
use dotenv::dotenv;
|
||||||
|
use std::env;
|
||||||
|
use std::str::FromStr;
|
||||||
|
use tower_http::trace::TraceLayer;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate diesel;
|
||||||
|
extern crate redis;
|
||||||
|
|
||||||
|
mod endpoints;
|
||||||
|
pub mod helpers;
|
||||||
|
pub mod migration;
|
||||||
|
pub mod models;
|
||||||
|
pub mod schema;
|
||||||
|
pub mod tests;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
dotenv().ok();
|
||||||
|
let _ = setup_logger();
|
||||||
|
|
||||||
|
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set");
|
||||||
|
|
||||||
|
migration::run_migrations(&db_url);
|
||||||
|
let manager = ConnectionManager::<InstrumentedPgConnection>::new(&db_url);
|
||||||
|
let pool = Pool::builder()
|
||||||
|
.build(manager)
|
||||||
|
.expect("Could not build connection pool");
|
||||||
|
|
||||||
|
let redis_url = env::var("REDIS_URL").unwrap_or(String::from("redis://localhost"));
|
||||||
|
let redis_client =
|
||||||
|
redis::Client::open(redis_url.as_str()).expect("Could not create redis client.");
|
||||||
|
|
||||||
|
let root = endpoints::get_routes()
|
||||||
|
.layer(TraceLayer::new_for_http())
|
||||||
|
.layer(AddExtensionLayer::new(RedisSessionStore::from_client(
|
||||||
|
redis_client,
|
||||||
|
)))
|
||||||
|
.layer(AddExtensionLayer::new(pool));
|
||||||
|
|
||||||
|
let ip = env::var("IP").unwrap_or(String::from("127.0.0.1"));
|
||||||
|
let port = env::var("PORT").unwrap_or(String::from("8000"));
|
||||||
|
let addr = SocketAddr::from((
|
||||||
|
IpAddr::from_str(ip.as_str()).unwrap_or(IpAddr::from(Ipv4Addr::new(127, 0, 0, 1))),
|
||||||
|
port.parse().unwrap_or(8000),
|
||||||
|
));
|
||||||
|
|
||||||
|
log::info!("started listening on {:?}", addr);
|
||||||
|
hyper::Server::bind(&addr)
|
||||||
|
.serve(root.into_make_service())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_logger() -> () {
|
||||||
|
let log_level = env::var("LOG_LEVEL").unwrap_or(String::from("INFO"));
|
||||||
|
let subscriber = tracing_subscriber::FmtSubscriber::builder()
|
||||||
|
.with_max_level(
|
||||||
|
tracing::Level::from_str(log_level.as_str()).unwrap_or(tracing::Level::INFO),
|
||||||
|
)
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
tracing_log::LogTracer::init().expect("could not init log tracer");
|
||||||
|
|
||||||
|
tracing::subscriber::set_global_default(subscriber).expect("could not set default subscriber");
|
||||||
|
// fern::Dispatch::new()
|
||||||
|
// .format(|out, message, record| {
|
||||||
|
// out.finish(format_args!(
|
||||||
|
// "{} <{}> [{}] {}",
|
||||||
|
// chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
|
||||||
|
// record.file().unwrap_or(record.target()),
|
||||||
|
// record.level(),
|
||||||
|
// message
|
||||||
|
// ))
|
||||||
|
// })
|
||||||
|
// .level(log::LevelFilter::from_str(log_level.as_str()).unwrap_or(log::LevelFilter::Info))
|
||||||
|
// .chain(std::io::stdout())
|
||||||
|
// .chain(fern::log_file("latest.log")?)
|
||||||
|
// .apply()?;
|
||||||
|
// Ok(())
|
||||||
|
}
|
|
@ -1,20 +1,19 @@
|
||||||
use crate::helpers::*;
|
use crate::helpers::*;
|
||||||
use crate::models::*;
|
use crate::models::*;
|
||||||
use diesel::{
|
use diesel::r2d2::{ConnectionManager, Pool};
|
||||||
r2d2::{ConnectionManager, Pool},
|
|
||||||
PgConnection,
|
use diesel_tracing::pg::InstrumentedPgConnection;
|
||||||
};
|
|
||||||
use std::{error::Error, vec::Vec};
|
use std::{error::Error, vec::Vec};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
async fn get_pool(url: &String) -> Pool<ConnectionManager<PgConnection>> {
|
async fn get_pool(url: &String) -> Pool<ConnectionManager<InstrumentedPgConnection>> {
|
||||||
let manager = ConnectionManager::<PgConnection>::new(url);
|
let manager = ConnectionManager::<InstrumentedPgConnection>::new(url);
|
||||||
Pool::builder()
|
Pool::builder()
|
||||||
.build(manager)
|
.build(manager)
|
||||||
.expect("Could not build connection pool")
|
.expect("Could not build connection pool")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn user_tests(pool: &Pool<ConnectionManager<PgConnection>>) {
|
async fn user_tests(pool: &Pool<ConnectionManager<InstrumentedPgConnection>>) {
|
||||||
let user = InsertableUser {
|
let user = InsertableUser {
|
||||||
discord_id: String::from("test"),
|
discord_id: String::from("test"),
|
||||||
};
|
};
|
||||||
|
@ -66,7 +65,7 @@ async fn user_tests(pool: &Pool<ConnectionManager<PgConnection>>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn block_tests(pool: &Pool<ConnectionManager<PgConnection>>) {
|
async fn block_tests(pool: &Pool<ConnectionManager<InstrumentedPgConnection>>) {
|
||||||
let json = serde_json::from_str("[]");
|
let json = serde_json::from_str("[]");
|
||||||
let block = InsertableBlock {
|
let block = InsertableBlock {
|
||||||
user_id: Uuid::new_v4(),
|
user_id: Uuid::new_v4(),
|