Skip to content

Commit

Permalink
fix: server scraping
Browse files Browse the repository at this point in the history
  • Loading branch information
sosweetham committed May 8, 2024
1 parent e1bc9f7 commit 338d8ae
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 29 deletions.
2 changes: 0 additions & 2 deletions app/src/controllers/user-avatar.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import { userAvatarBucket, guildedUserProfileScrape, streamToBuffer } from "../l
export const userAvatarController = new Elysia()
.get('/:id', async ({ params }) => {
if (await userAvatarBucket.checkAssetExists(params.id)) {
console.log('User avatar exists')
const lastModified = await userAvatarBucket.getAssetLastModified(params.id)
if (Date.now() - lastModified.valueOf() > 24 * 60 * 60 * 1000) {
(async () => guildedUserProfileScrape(params.id, 'avatar'))().catch((e) => console.error(e))
}
console.log('Sending cached avatar')
const avatar = await userAvatarBucket.getAsset(params.id)
const res = new Response(await streamToBuffer(avatar), { headers: { 'Content-Type': 'image/webp' } })
return res
Expand Down
2 changes: 1 addition & 1 deletion app/src/libs/guilded-scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const guildedServerProfileScrape: (id: string, getElement: 'icon' | 'bann
if (!server) {
return new Error('Server not found')
}
const src = getElement === 'icon' ? guildedMediaLink(server.profilePicture) : guildedMediaLink(server.teamDashImage)
const src = getElement === 'icon' ? guildedMediaLink(server.team.profilePicture) : guildedMediaLink(server.team.teamDashImage)
const signed = await(await fetch(`https://www.guilded.gg/api/v1/url-signatures`, {
method: 'POST',
headers: {
Expand Down
45 changes: 45 additions & 0 deletions dev.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: '3.7'

# Settings and configurations that are common for all containers
x-minio-common: &minio-common
image: quay.io/minio/minio:RELEASE.2024-05-01T01-11-10Z
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:?Enter the Minio Root User}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?Enter the Minio Root Password}
MINIO_CONSOLE_PORT: ${MINIO_CONSOLE_PORT:?Enter the Minio Console Port}
MINIO_PORT: ${MINIO_PORT:?Enter the Minio Port}
command: server --console-address ":${MINIO_CONSOLE_PORT}" /mnt/data
ports:
- "${MINIO_CONSOLE_PORT}:${MINIO_CONSOLE_PORT}"
- "${MINIO_PORT}:9000"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3

services:
photobox-minio1:
<<: *minio-common
container_name: photobox-minio1
hostname: photobox-minio1
volumes:
- ./minio/data:/mnt/data
photobox-app:
environment:
PORT: ${PORT:?Enter the Port Number to Run the app on}
MINIO_HOST: photobox-minio1
MINIO_PORT: 9000
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY:?Enter the Minio Access Key from the Admin Dashboard}
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY:?Enter the Minio Secret Key from the Admin Dashboard}
G_TOKEN: ${G_TOKEN:?Enter the Guilded Token}
build:
context: .
dockerfile: ./docker/dev/app.dockerfile
container_name: photobox-app
volumes:
- ./app:/app
ports:
- "${PORT}:${PORT}"
depends_on:
- photobox-minio1
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ services:
G_TOKEN: ${G_TOKEN:?Enter the Guilded Token}
build:
context: .
dockerfile: ./docker/app.dockerfile
dockerfile: ./docker/prod/app.dockerfile
container_name: photobox-app
volumes:
- ./app:/app
Expand Down
25 changes: 0 additions & 25 deletions docker/app.dockerfile

This file was deleted.

7 changes: 7 additions & 0 deletions docker/dev/app.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM oven/bun:1.1.7-debian

WORKDIR /app

COPY ./app/package.json ./

CMD bun i; bun dev;
7 changes: 7 additions & 0 deletions docker/prod/app.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM oven/bun:1.1.7-debian

WORKDIR /app

COPY ./app/package.json ./

CMD bun i; bun start;

0 comments on commit 338d8ae

Please sign in to comment.