Skip to content
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
44 changes: 44 additions & 0 deletions .github/workflows/aio-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and Publish aio-dev

on:
push:
branches:
- dev

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Bun
uses: oven-sh/setup-bun@v1

- name: Install dependencies and build web app
run: |
cd apps/web
bun install
bun run build

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and Push Multi-Arch Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ secrets.DOCKER_USERNAME }}/dashwise:aio-dev
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dist/

# testing
/coverage
docker-compose.test.testenv.yaml

# Ignore everything under /pocketbase
/pocketbase/*
Expand Down
53 changes: 53 additions & 0 deletions apps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import systemRoute from "./routes/system.route";
import dataRoute from "./routes/data.route";

const app = new Hono();
const devAutoLoginEmail = "testenv@dashwise.local";
const devAutoLoginPassword = "DashwiseTestenv123";
const assetRoots = {
defaults: resolve(process.cwd(), "../../packages/assets/defaults"),
integrations: resolve(process.cwd(), "../../packages/assets/integrations"),
Expand Down Expand Up @@ -203,6 +205,56 @@ app.get("*", async () => {

const port = config.PORT;

async function printDevAutoLoginUrl() {
if (Bun.env.NODE_ENV !== "development") {
return;
}

const apiUrl = `http://127.0.0.1:${port}`;
const appUrl = Bun.env.NEXT_PUBLIC_APP_URL || "http://localhost:5173";

try {
const signupResponse = await fetch(`${apiUrl}/api/v1/auth/signup`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: devAutoLoginEmail,
password: devAutoLoginPassword,
passwordConfirm: devAutoLoginPassword,
}),
});

if (![200, 201, 400].includes(signupResponse.status)) {
logger.warn(`Dev auto-login signup returned HTTP ${signupResponse.status}`);
}

const loginResponse = await fetch(`${apiUrl}/api/v1/auth/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: devAutoLoginEmail,
password: devAutoLoginPassword,
}),
});

if (!loginResponse.ok) {
logger.warn(`Dev auto-login failed with HTTP ${loginResponse.status}`);
return;
}

const loginData = await loginResponse.json() as { token?: string };
if (!loginData.token) {
logger.warn("Dev auto-login response did not include a token");
return;
}

logger.info(`Dev auto-login URL: ${appUrl}/auth?loginToken=${encodeURIComponent(loginData.token)}`);
logger.info(`Dev credentials: ${devAutoLoginEmail} / ${devAutoLoginPassword}`);
} catch (error) {
logger.warn(`Dev auto-login setup failed: ${error instanceof Error ? error.message : String(error)}`);
}
}

Bun.serve({
hostname: "0.0.0.0",
port,
Expand All @@ -212,6 +264,7 @@ Bun.serve({

logger.info(`Running on 0.0.0.0:${port}`);
logger.info(`PocketBase target URL: ${config.PB_URL}`);
void printDevAutoLoginUrl();

export type AppType = typeof app;
export { app };
20 changes: 17 additions & 3 deletions apps/backend/src/jobs/news/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export interface FeedItem {

const logger = createLogger("NewsFeedBuilder");

const FEED_REQUEST_HEADERS = {
"User-Agent": "Dashwise RSS Reader (+https://github.com/andrew-d/dashwise)",
"Accept": "application/rss+xml, application/atom+xml, application/xml, text/xml;q=0.9, */*;q=0.8",
};

type ParserItem = Parser.Item & {
author?: string;
creator?: string;
Expand Down Expand Up @@ -50,6 +55,7 @@ export async function getFeedItems({
const logger = createLogger("NewsFeedBuilder");

const parser = new Parser<any, ParserItem>({
headers: FEED_REQUEST_HEADERS,
customFields: {
item: [
["media:thumbnail", "media:thumbnail"],
Expand Down Expand Up @@ -80,7 +86,7 @@ export async function getFeedItems({
return {
title: stripHtml(item.title) || "No Title",
link,
description: getBestDescription(item),
description: truncateSentences(getBestDescription(item), 5),
content: getContent(item),
pubDate,
thumbnailUrl: getThumbnail(item, thumbnailOverwriteUrl, fallbackThumbnailUrl || feed?.image?.url),
Expand All @@ -92,7 +98,7 @@ export async function getFeedItems({
.slice(0, maxItems);
} catch (error: any) {
logger.error(`Error fetching or parsing feed: ${feedUrl}`, error);
return [];
throw error;
}
}

Expand Down Expand Up @@ -121,6 +127,14 @@ function getBestDescription(item: ParserItem): string {
);
}

function truncateSentences(value: string, maxSentences: number): string {
const text = stripHtml(value).trim();
if (!text) return "";

const sentences = text.match(/[^.!?]+[.!?]+(?:\s+|$)|[^.!?]+$/g) ?? [text];
return sentences.slice(0, maxSentences).join(" ").replace(/\s+/g, " ").trim();
}

function getContent(item: ParserItem): string | undefined {
const raw =
item.content ??
Expand Down Expand Up @@ -242,4 +256,4 @@ export function getThumbnail(
];

return candidates.find((c) => c && /^https?:\/\//i.test(c));
}
}
Loading