Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/1.19.1 #69

Merged
merged 3 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/dataimport/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,25 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Install Firefox
RUN apt-get update && \
apt-get install -y --no-install-recommends firefox-esr && \
rm -rf /var/lib/apt/lists/*
apt-get install -y --no-install-recommends firefox-esr

# Install GeckoDriver
RUN apt-get update && \
apt-get install -y --no-install-recommends wget unzip && \
RUN apt-get install -y --no-install-recommends wget unzip && \
wget https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz && \
tar -xvzf geckodriver-v0.30.0-linux64.tar.gz && \
rm geckodriver-v0.30.0-linux64.tar.gz && \
chmod +x geckodriver && \
mv geckodriver /usr/local/bin/ && \
apt-get remove -y wget unzip && \
rm -rf /var/lib/apt/lists/*
apt-get remove -y wget unzip

# Install rsyslog
RUN apt-get update && apt-get install -y rsyslog
COPY rsyslog.conf /etc/rsyslog.conf
RUN chmod 644 /etc/rsyslog.conf
# Install deps
RUN apt-get install -y rsyslog cron dos2unix libmagic1

# Install cron
RUN apt-get update && apt-get install -y cron
# Cleanup
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install dos2unix
RUN apt-get update && apt-get install -y dos2unix
COPY rsyslog.conf /etc/rsyslog.conf
RUN chmod 644 /etc/rsyslog.conf

COPY . /app

Expand Down
2 changes: 1 addition & 1 deletion src/dataimport/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pyotp==2.9.0
instagrapi==2.0.1
pillow==10.3.0
blinker==1.7.0
tweety-ns==1.1.9
tweety-ns==2.0.6
httpx==0.27.2
h2==4.1.0
httpx[http2]
2 changes: 1 addition & 1 deletion src/dataimport/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async def twitter():

console.log("Fetching last tweets of list...")

contents = app.get_list_tweets(LIST_ID)
contents = await app.get_list_tweets(LIST_ID)
for content in contents:
if isinstance(content, Tweet):
await handle_tweet(content, db)
Expand Down
40 changes: 12 additions & 28 deletions src/imageresizer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ app.get("/_health", (_, res) => {

app.get("/cdn/:dir/:filename", async (req: Request<{ dir: string; filename: string }>, res: Response) => {
let { dir, filename } = req.params;
const { width, format } = req.query;
const { width } = req.query;

if (!filename) {
logger.error("Missing filename parameter");
Expand All @@ -46,7 +46,6 @@ app.get("/cdn/:dir/:filename", async (req: Request<{ dir: string; filename: stri
}

// Validate parameters
const validFormats = ["avif", "jpg"];
const validWidths = ["300", "768", "original"];

if (width && !validWidths.includes(width.toString())) {
Expand All @@ -55,36 +54,21 @@ app.get("/cdn/:dir/:filename", async (req: Request<{ dir: string; filename: stri
return;
}

if (format && !validFormats.includes(format.toString())) {
logger.error(`Invalid format parameter: "${format}"`);
res.status(400).send("Invalid format parameter, must be one of: avif, jpg");
return;
}

const targetFormat = (format as "avif" | "jpg") || "jpg";
const targetWidth = width ? (width === "original" ? undefined : parseInt(width.toString())) : undefined;

const originalFilePath = path.join(cdnFiles, filename);
if (!fs.existsSync(originalFilePath)) {
logger.error(`Original Resource not found: "${originalFilePath}"`);
res.status(404).send("Resource not found");
return;
}

// convert image to specified format and size
let specificFileName = filename;
if (targetWidth !== undefined || targetFormat !== "jpg") {
if (targetWidth) {
specificFileName = `${filename.split(".")[0]}-w${targetWidth}.${targetFormat}`;
} else {
specificFileName = `${filename.split(".")[0]}.${targetFormat}`;
}
}

const originalFilePath = path.join(cdnFiles, filename);
const specificFileName = targetWidth === undefined ? filename : `${filename.split(".")[0]}-w${targetWidth}.jpg`;
const specificFilePath = path.join(cdnFiles, specificFileName);
logger.info(`Serving image: "${specificFilePath}"`);

if (!fs.existsSync(specificFilePath)) {
if (specificFileName === filename && !fs.existsSync(originalFilePath)) {
logger.error(`Original Resource not found: "${originalFilePath}"`);
res.status(404).send("Resource not found");
return;
}

logger.info(`Generating image: "${specificFilePath}" from "${originalFilePath}"`);

try {
Expand All @@ -93,17 +77,17 @@ app.get("/cdn/:dir/:filename", async (req: Request<{ dir: string; filename: stri
image.resize(targetWidth);
}

image.toFormat(targetFormat, { quality: 100 });
image.toFormat("jpg", { quality: 100 });

await image.toFile(specificFilePath);
} catch (error) {
logger.error(`Failed to generate image: "${specificFilePath}"`);
logger.error(`Failed to generate image: "${specificFilePath}"`, error);
res.status(500).send("Failed to generate image");
return;
}
}

res.contentType(`image/${targetFormat}`);
res.contentType(`image/jpg`);
res.sendFile(specificFilePath);
});

Expand Down
4 changes: 2 additions & 2 deletions src/psaggregator/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/psaggregator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "psaggregator",
"version": "1.19.0",
"version": "1.19.1",
"scripts": {
"dev": "vite dev",
"build": "vite build",
Expand Down
25 changes: 1 addition & 24 deletions src/psaggregator/src/lib/components/CDNImage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,6 @@

let imageSrc = "";

function supportsAVIF() {
return new Promise((resolve) => {
const avifImage =
"data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=";
const img = new Image();
img.onload = () => resolve(true);
img.onerror = () => resolve(false);
img.src = avifImage;
});
}

async function getPreferredImageFormat() {
if (!browser || !window || !window.matchMedia) {
return "jpg";
}

if (await supportsAVIF()) {
return "avif";
}

return "jpg"; // fallback
}

function getPreferredImageSize(): "300" | "768" | "original" {
if (!browser || !window || !window.matchMedia) {
return "300";
Expand Down Expand Up @@ -63,7 +40,7 @@
}

async function calculateImageSrc(src: string | null | undefined) {
imageSrc = `${src}?format=${await getPreferredImageFormat()}&width=${getPreferredImageSize()}`;
imageSrc = `${src}?width=${getPreferredImageSize()}`;
}

$: browser && calculateImageSrc(src);
Expand Down
2 changes: 1 addition & 1 deletion src/psaggregator/src/lib/components/InstagramPost.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
src={resource.imageUri}
alt={resource.remoteId}
title={resource.remoteId}
loading="lazy" />
{loading} />
</div>
{/each}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@
src={selectedStory.imageUri}
alt={selectedStory.text}
title={selectedStory.text}
class="rounded-[20px] object-contain" />
class="rounded-[20px] object-contain"
loading="eager" />
{/if}
{/if}
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/psaggregator/src/routes/changelog/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
</style>

<div class="flex-col p-4">
<h2 class="mb-2 text-2xl font-bold">Version 1.19.1</h2>
<div class="changelog-contents w-full grow overflow-y-auto lg:w-1/2">
<h3 class="mb-2 text-xl font-bold">Überarbeitungen</h3>
<div>
<span>Twitter-Import</span>
<span>Ein Problem beim Twitter-Import wurde behoben. Tweets sollten nun wieder korrekt importiert werden.</span>
</div>
</div>

<h2 class="mb-2 text-2xl font-bold">Version 1.19.0</h2>
<div class="changelog-contents w-full grow overflow-y-auto lg:w-1/2">
<h3 class="mb-2 text-xl font-bold">Neue Features</h3>
Expand Down