1
0
mirror of https://github.com/barthuijgen/factorio-sites.git synced 2025-03-05 16:07:29 +02:00

Update readmes, add fonts locally, fixes to search page props

This commit is contained in:
Bart 2021-03-13 15:15:15 +01:00
parent bf62516501
commit 8e126697b6
18 changed files with 107 additions and 55 deletions

View File

@ -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`

View File

@ -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) {

View File

@ -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`

View File

@ -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
```

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -57,7 +57,7 @@ const formatDate = (datenum: number) => {
};
interface BlueprintLinkProps {
blueprint: BlueprintPage;
blueprint: Pick<BlueprintPage, "id" | "title" | "image_hash" | "favorite_count" | "updated_at">;
editLink?: boolean;
type: "tile" | "row";
}

View File

@ -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 = ({
<Head>
<title>Factorio Blueprints</title>
<link rel="shortcut icon" href="/favicon.png" />
<link href="https://cdn.factorio.com/assets/fonts/titillium-web.css" rel="stylesheet" />
<meta name="description" content="Find blueprints for Factorio with advanced search" />
</Head>
{!auth.loading && (
<>

View File

@ -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<IndexProps> = ({
@ -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,
};
}