diff --git a/README.md b/README.md index 02d102d..8896ebe 100644 --- a/README.md +++ b/README.md @@ -22,35 +22,6 @@ This amazing project allows us to render real time high quality images directly - A postgres database (docker-compose.yml provided) - A Google Cloud Platform project -## Setting up the project +## Run factorioblueprints.tech locally -- Add a `.env.local` file to apps/blueprints/ with the following values - -``` -POSTGRES_DB=factorio-blueprints -POSTGRES_USER=factorio-blueprints -#POSTGRES_HOST=127.0.0.1 -#POSTGRES_PASSWORD=local -STEAM_WEB_API_KEY=(optional, for steam login) -GOOGLE_APPLICATION_CREDENTIALS="full/path/to/json-key-file.json" -GCP_BLUEPRINT_STRINGS_BUCKET=blueprint-strings -GCP_BLUEPRINT_IMAGES_BUCKET=blueprint-images -``` - -- Add a `.env` file to apps/blueprints/prisma with a database connection url like - -``` -DATABASE_URL="postgresql://factorio-blueprints:local@127.0.0.1:5432/factorio-blueprints" -``` - -- Run DB migration - -``` -cd apps/blueprints && npx prisma migrate deploy --preview-feature -``` - -- Run local app - -``` -nx serve -``` +- See `/apps/blueprints/README.md` diff --git a/apps/blueprint-image-function/src/pubsub-render.ts b/apps/blueprint-image-function/src/pubsub-render.ts index e23d155..06b097a 100644 --- a/apps/blueprint-image-function/src/pubsub-render.ts +++ b/apps/blueprint-image-function/src/pubsub-render.ts @@ -36,15 +36,16 @@ export async function subscribeToPubSub() { }; try { - if (!message.attributes.blueprintId) { + const data = JSON.parse(message.data.toString("utf-8")); + if (!data.blueprintId) { return ack("blueprintId not found in message body", false); } console.log("------------------------------------------------"); - console.log("[pubsub] generating image for", message.attributes.blueprintId); - const blueprint = await getBlueprintById(message.attributes.blueprintId); + console.log("[pubsub] generating image for", data.blueprintId); + const blueprint = await getBlueprintById(data.blueprintId); if (!blueprint) return ack("Blueprint not found", false); - if (await hasBlueprintImage(blueprint.image_hash)) { + if (await hasBlueprintImage(blueprint.image_hash, "300")) { return ack("Image already exists", true); } @@ -54,9 +55,9 @@ export async function subscribeToPubSub() { const image = await renderImage(blueprint_string); console.log(`[pubsub] image generated`); - const min_image = await optimise(image); + const min_image = await optimise(image, 300); - await saveBlueprintImage(blueprint.image_hash, min_image); + await saveBlueprintImage(blueprint.image_hash, min_image, "300"); return ack("[pubsub] image saved", true); } catch (reason) { diff --git a/apps/blueprints/README.md b/apps/blueprints/README.md index 6572161..285eaaa 100644 --- a/apps/blueprints/README.md +++ b/apps/blueprints/README.md @@ -1,17 +1,40 @@ -## Before deploying +# Blueprints application -Make sure `prod.package.json` is up to date on packages from the root `package.json` +## Setting up the project + +- Add a `.env.local` file to apps/blueprints/ with the following values + +``` +POSTGRES_DB=factorio-blueprints +POSTGRES_USER=factorio-blueprints +#POSTGRES_HOST=127.0.0.1 +#POSTGRES_PASSWORD=local +STEAM_WEB_API_KEY=(optional, for steam login) +GOOGLE_APPLICATION_CREDENTIALS="full/path/to/json-key-file.json" +GCP_BLUEPRINT_STRINGS_BUCKET=blueprint-strings +GCP_BLUEPRINT_IMAGES_BUCKET=blueprint-images +``` + +- Add a `.env` file to apps/blueprints/prisma with a database connection url like + +``` +DATABASE_URL="postgresql://factorio-blueprints:local@127.0.0.1:5432/factorio-blueprints" +``` + +- Run DB migration + +``` +cd apps/blueprints && npx prisma migrate deploy --preview-feature +``` + +- Run local app + +``` +nx serve +``` ## Deploying -`docker build -t eu.gcr.io/factorio-sites/blueprints --file blueprints.Dockerfile .` -`docker tag eu.gcr.io/factorio-sites/blueprints eu.gcr.io/factorio-sites/blueprints:dev` -`docker push eu.gcr.io/factorio-sites/blueprints` - -### windows env - -create a `.env.local` with - -``` -GOOGLE_APPLICATION_CREDENTIALS="D:\git\factorio-sites\credentials\factorio-sites.json" -``` +- `docker build -t eu.gcr.io/factorio-sites/blueprints --file blueprints.Dockerfile .` +- `docker tag eu.gcr.io/factorio-sites/blueprints eu.gcr.io/factorio-sites/blueprints:dev` +- `docker push eu.gcr.io/factorio-sites/blueprints` diff --git a/apps/blueprints/prisma/dev.md b/apps/blueprints/prisma/dev.md new file mode 100644 index 0000000..a03c158 --- /dev/null +++ b/apps/blueprints/prisma/dev.md @@ -0,0 +1,29 @@ +# Some dev queries to maintain the database + +### Resources + +- https://www.postgresql.org/docs/9.5/functions-json.html + +### Find all icons + +``` +SELECT distinct concat(type,'/',name) FROM blueprint, jsonb_to_recordset(data -> 'icons') as icons(name text,type text) +``` + +### Unique entities + +``` +SELECT distinct UNNEST(ARRAY(SELECT jsonb_object_keys(data -> 'entities'))) as entities FROM blueprint +``` + +### Unique items + +``` +SELECT distinct UNNEST(ARRAY(SELECT jsonb_object_keys(data -> 'items'))) as entities FROM blueprint +``` + +### Unique recipes + +``` +SELECT distinct UNNEST(ARRAY(SELECT jsonb_object_keys(data -> 'recipes'))) as entities FROM blueprint +``` diff --git a/apps/blueprints/public/fonts/TitilliumWeb-Black.ttf b/apps/blueprints/public/fonts/TitilliumWeb-Black.ttf new file mode 100644 index 0000000..ec5b093 Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-Black.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-Bold.ttf b/apps/blueprints/public/fonts/TitilliumWeb-Bold.ttf new file mode 100644 index 0000000..b51a4d6 Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-Bold.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-BoldItalic.ttf b/apps/blueprints/public/fonts/TitilliumWeb-BoldItalic.ttf new file mode 100644 index 0000000..d0fe23b Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-BoldItalic.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-ExtraLight.ttf b/apps/blueprints/public/fonts/TitilliumWeb-ExtraLight.ttf new file mode 100644 index 0000000..a590b73 Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-ExtraLight.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-ExtraLightItalic.ttf b/apps/blueprints/public/fonts/TitilliumWeb-ExtraLightItalic.ttf new file mode 100644 index 0000000..8fe0256 Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-ExtraLightItalic.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-Italic.ttf b/apps/blueprints/public/fonts/TitilliumWeb-Italic.ttf new file mode 100644 index 0000000..266d5cb Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-Italic.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-Light.ttf b/apps/blueprints/public/fonts/TitilliumWeb-Light.ttf new file mode 100644 index 0000000..fbba05d Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-Light.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-LightItalic.ttf b/apps/blueprints/public/fonts/TitilliumWeb-LightItalic.ttf new file mode 100644 index 0000000..3783f8d Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-LightItalic.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-Regular.ttf b/apps/blueprints/public/fonts/TitilliumWeb-Regular.ttf new file mode 100644 index 0000000..a54ad4b Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-Regular.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-SemiBold.ttf b/apps/blueprints/public/fonts/TitilliumWeb-SemiBold.ttf new file mode 100644 index 0000000..49109f8 Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-SemiBold.ttf differ diff --git a/apps/blueprints/public/fonts/TitilliumWeb-SemiBoldItalic.ttf b/apps/blueprints/public/fonts/TitilliumWeb-SemiBoldItalic.ttf new file mode 100644 index 0000000..22243ff Binary files /dev/null and b/apps/blueprints/public/fonts/TitilliumWeb-SemiBoldItalic.ttf differ diff --git a/apps/blueprints/src/components/BlueprintLink.tsx b/apps/blueprints/src/components/BlueprintLink.tsx index 578f6e4..b2efa0f 100644 --- a/apps/blueprints/src/components/BlueprintLink.tsx +++ b/apps/blueprints/src/components/BlueprintLink.tsx @@ -57,7 +57,7 @@ const formatDate = (datenum: number) => { }; interface BlueprintLinkProps { - blueprint: BlueprintPage; + blueprint: Pick; editLink?: boolean; type: "tile" | "row"; } diff --git a/apps/blueprints/src/pages/_app.tsx b/apps/blueprints/src/pages/_app.tsx index a80fe15..9f81300 100644 --- a/apps/blueprints/src/pages/_app.tsx +++ b/apps/blueprints/src/pages/_app.tsx @@ -10,6 +10,25 @@ import { useFetch } from "../hooks/fetch"; import { getSessionToken } from "@factorio-sites/node-utils"; const globalStyles = css` + @font-face { + font-family: titillium web; + font-style: normal; + font-weight: 400; + src: url(/fonts/TitilliumWeb-Regular.ttf); + } + @font-face { + font-family: titillium web; + font-style: normal; + font-weight: 600; + src: url(/fonts/TitilliumWeb-SemiBold.ttf); + } + @font-face { + font-family: titillium web; + font-style: normal; + font-weight: 700; + src: url(/fonts/TitilliumWeb-Bold.ttf); + } + html { height: 100%; font-size: 100%; @@ -60,7 +79,7 @@ const BlueprintsApp = ({ Factorio Blueprints - + {!auth.loading && ( <> diff --git a/apps/blueprints/src/pages/index.tsx b/apps/blueprints/src/pages/index.tsx index 847befe..c013183 100644 --- a/apps/blueprints/src/pages/index.tsx +++ b/apps/blueprints/src/pages/index.tsx @@ -51,7 +51,10 @@ interface IndexProps { totalItems: number; currentPage: number; totalPages: number; - blueprints: BlueprintPage[]; + blueprints: Pick< + BlueprintPage, + "id" | "image_hash" | "favorite_count" | "title" | "updated_at" + >[]; } export const Index: NextPage = ({ @@ -230,8 +233,14 @@ export async function getServerSideProps({ query }: NextPageContext) { totalItems: count, currentPage: page, totalPages: Math.ceil(count / perPage), - blueprints: rows, - }, + blueprints: rows.map((row) => ({ + id: row.id, + image_hash: row.image_hash, + favorite_count: row.favorite_count, + title: row.title, + updated_at: row.updated_at, + })), + } as IndexProps, }; }