Skip to content

Commit

Permalink
Merge pull request #98 from Suwayomi/main
Browse files Browse the repository at this point in the history
MU tracking
  • Loading branch information
Robonau authored Nov 26, 2023
2 parents 150769d + fe67da8 commit 6f4f9b4
Show file tree
Hide file tree
Showing 18 changed files with 976 additions and 50 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
FROM oven/bun:1.0.10-alpine as develop-stage
WORKDIR /app
COPY . .
ARG version="DevBuild"
RUN sed -i "s@BUILD_VERSION_PLACEHOLDER@${version}@" ./src/app.html
RUN sed -i "s@TRACKING_PLACEHOLDER@Docker@" ./src/app.html
# build stage
FROM develop-stage as build-stage
RUN bun install
RUN bun run build
ARG version="DevBuild"
RUN sed -i "s@BUILD_VERSION_PLACEHOLDER@${version}@" ./build/index.html
# production stage
FROM nginxinc/nginx-unprivileged:1.23.2-alpine-slim as production-stage
USER root
Expand Down
Binary file modified bun.lockb
Binary file not shown.
9 changes: 9 additions & 0 deletions default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ server {
proxy_set_header Connection $http_connection;
proxy_set_header Upgrade $http_upgrade;
}

location /v1 {
resolver 127.0.0.11 valid=30s;
set $upstreame https://api.mangaupdates.com;
proxy_pass $upstreame;
proxy_http_version 1.1;
proxy_set_header Connection $http_connection;
proxy_set_header Upgrade $http_upgrade;
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
"@sveltejs/adapter-static": "^2.0.3",
"@types/apollo-upload-client": "^17.0.2",
"@types/dom-view-transitions": "^1.0.3",
"@types/sanitize-html": "^2.9.5",
"apollo-upload-client": "^17.0.0",
"devalue": "^4.3.2",
"graphql": "^16.8.1",
"graphql-codegen-svelte-apollo": "^1.1.0",
"graphql-ws": "^5.14.2",
"p-queue": "^7.4.1",
"sanitize-html": "^2.11.0",
"sveltekit-search-params": "^1.0.15"
}
}
3 changes: 2 additions & 1 deletion src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ declare namespace App {
}

declare interface Window {
version: string | undefined;
version: string;
tracking: 'docker' | 'TRACKING_PLACEHOLDER';
}

declare interface Navigator {
Expand Down
1 change: 1 addition & 0 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width" />
<script>
window.version = 'BUILD_VERSION_PLACEHOLDER';
window.tracking = 'TRACKING_PLACEHOLDER';
</script>
<!-- if i need to add UI env variables in the future -->
<!-- <script>
Expand Down
41 changes: 30 additions & 11 deletions src/lib/simpleStores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ const mangaMetaDefaults = {
NavLayout: Layout.L,
preLoadNextChapter: true,
mobileFullScreenOnChapterPage: true,
doPageIndicator: false
doPageIndicator: false,
mangaUpdatesSeriesID: null as null | number
};
type mangaMeta = typeof mangaMetaDefaults;

Expand Down Expand Up @@ -100,12 +101,18 @@ const trueDefaults = {
Downloaded: 0 as TriState,
mangaMetaDefaults,
downloadsBadge: true,
unreadbadge: true
unreadBadge: true,
mangaUpdatesTracking: {
enabled: false,
username: '',
password: '',
Authorization: ''
}
};

type globalMeta = typeof trueDefaults;

function GlobalMetaUpdator(cache: ApolloCache<unknown>, key: string, value: string) {
function GlobalMetaUpdater(cache: ApolloCache<unknown>, key: string, value: string) {
const { metas: tmp } = structuredClone(
cache.readQuery({
query: MetasDoc
Expand All @@ -125,7 +132,12 @@ function GlobalMetaUpdator(cache: ApolloCache<unknown>, key: string, value: stri
function GlobalMeta() {
const Meta = metas({});
const store = localStorageStore('GlobalMeta', trueDefaults);

if (get(store).mangaUpdatesTracking === undefined) {
store.update((n) => {
n.mangaUpdatesTracking = trueDefaults.mangaUpdatesTracking;
return n;
});
}
Meta.subscribe((e) => {
store.update((n) => {
const Ncopy = structuredClone(get(store)) as { [key: string]: unknown };
Expand All @@ -146,20 +158,20 @@ function GlobalMeta() {
if (value !== tmp)
try {
//update before waiting
GlobalMetaUpdator(cache, key, value);
GlobalMetaUpdater(cache, key, value);
if (value !== JSON.stringify(trueDefaults[entry[0]])) {
//set if not the truedefault value
await setGlobalMeta({
variables: { key, value },
//update after to keep in sync
update: (a) => GlobalMetaUpdator(a, key, value)
update: (a) => GlobalMetaUpdater(a, key, value)
});
} else if (tmp !== undefined) {
//delete if not already undefined
await deleteGlobalMeta({
variables: { key: key },
//update after to keep in sync
update: (a) => GlobalMetaUpdator(a, key, value)
update: (a) => GlobalMetaUpdater(a, key, value)
});
}
} catch {}
Expand All @@ -179,7 +191,7 @@ function GlobalMeta() {

export const Meta = GlobalMeta();

function MangaMetaUpdator(cache: ApolloCache<unknown>, key: string, value: string, id: number) {
function MangaMetaUpdater(cache: ApolloCache<unknown>, key: string, value: string, id: number) {
const { manga } = structuredClone(
cache.readQuery({
query: GetMangaDoc,
Expand All @@ -202,6 +214,13 @@ export function MangaMeta(id: number) {
const MMeta = getManga({ variables: { id } });
const store = writable(get(Meta).mangaMetaDefaults);

if (get(store).mangaUpdatesSeriesID === undefined) {
store.update((n) => {
n.mangaUpdatesSeriesID = mangaMetaDefaults.mangaUpdatesSeriesID;
return n;
});
}

MMeta.subscribe((e) => {
store.update((n) => {
const Ncopy = structuredClone(get(store)) as { [key: string]: unknown };
Expand All @@ -222,20 +241,20 @@ export function MangaMeta(id: number) {
if (value !== tmp)
try {
//update before waiting
MangaMetaUpdator(cache, key, value, id);
MangaMetaUpdater(cache, key, value, id);
if (entry[1] !== get(Meta).mangaMetaDefaults[entry[0]]) {
//set if not the truedefault value
await setMangaMeta({
variables: { key, value, id }
//update after to keep in sync
// update: (a) => MangaMetaUpdator(a, key, value, id)
// update: (a) => MangaMetaUpdater(a, key, value, id)
});
} else if (tmp !== undefined) {
//delete if not already undefined
await deleteMangaMeta({
variables: { key, id }
//update after to keep in sync
// update: (a) => MangaMetaUpdator(a, key, value, id)
// update: (a) => MangaMetaUpdater(a, key, value, id)
});
}
} catch {}
Expand Down
Loading

0 comments on commit 6f4f9b4

Please sign in to comment.