chore: transfer hotpatches
Some checks failed
Build and Publish Docker Image / build-publish (push) Has been cancelled

This commit is contained in:
William Oldham 2025-01-16 12:44:52 +00:00
parent 0cd9b63041
commit 233a82697a
5 changed files with 30 additions and 5 deletions

View File

@ -25,6 +25,7 @@ export const config: Config = {
connection_string: process.env.PN_MIIVERSE_API_CONFIG_MONGO_CONNECTION_STRING || '',
options: mongooseConnectOptionsMain
},
cdn_url: process.env.PN_MIIVERSE_API_CONFIG_CDN_URL || '',
s3: {
endpoint: process.env.PN_MIIVERSE_API_CONFIG_S3_ENDPOINT || '',
key: process.env.PN_MIIVERSE_API_CONFIG_S3_ACCESS_KEY || '',
@ -64,6 +65,21 @@ if (!config.mongoose.connection_string) {
process.exit(0);
}
if (!config.cdn_url) {
LOG_ERROR('Failed to find CDN url. Set the PN_MIIVERSE_API_CONFIG_CDN_URL environment variable');
process.exit(0);
}
try {
new URL(config.cdn_url);
} catch (e) {
LOG_ERROR('Invalid CDN URL, URL must be a valid URL with a protocol (http/https) and domain');
process.exit(0);
}
// Remove trailing slash from CDN URL
config.cdn_url = config.cdn_url.replace(/\/$/, '');
if (!config.s3.endpoint) {
LOG_ERROR('Failed to find s3 endpoint. Set the PN_MIIVERSE_API_CONFIG_S3_ENDPOINT environment variable');
process.exit(0);

View File

@ -18,6 +18,7 @@ import { LOG_WARN } from '@/logger';
import { Post } from '@/models/post';
import { Conversation } from '@/models/conversation';
import { FormattedMessage } from '@/types/common/formatted-message';
import { config } from '@/config-manager';
const sendMessageSchema = z.object({
body: z.string().optional(),
@ -195,7 +196,7 @@ router.post('/', upload.none(), async function (request: express.Request, respon
is_app_jumpable: request.body.is_app_jumpable,
language_id: request.body.language_id,
mii: sender.mii.data,
mii_face_url: `https://mii.olv.pretendo.cc/mii/${sender.pid}/${miiFace}`,
mii_face_url: `${config.cdn_url}/mii/${sender.pid}/${miiFace}`,
pid: request.pid,
platform_id: request.paramPack.platform_id,
region_id: request.paramPack.region_id,

View File

@ -24,6 +24,7 @@ import { Post } from '@/models/post';
import { Community } from '@/models/community';
import { HydratedPostDocument } from '@/types/mongoose/post';
import { PostRepliesResult } from '@/types/miiverse/post';
import { config } from '@/config-manager';
const newPostSchema = z.object({
community_id: z.string().optional(),
@ -218,7 +219,7 @@ async function newPost(request: express.Request, response: express.Response): Pr
let user: GetUserDataResponse;
try {
user = await getUserAccountData(request.pid);
user = await getUserAccountData(request.pid);
} catch (error) {
// TODO - Log this error
response.sendStatus(403);
@ -364,7 +365,7 @@ async function newPost(request: express.Request, response: express.Response): Pr
is_app_jumpable: (jumpable) ? 1 : 0,
language_id: languageID,
mii: user.mii.data,
mii_face_url: `https://mii.olv.pretendo.cc/mii/${user.pid}/${miiFace}`,
mii_face_url: `${config.cdn_url}/mii/${user.pid}/${miiFace}`,
pid: request.pid,
platform_id: platformID,
region_id: regionID,

View File

@ -9,6 +9,7 @@ export interface Config {
connection_string: string;
options: mongoose.ConnectOptions;
};
cdn_url: string;
s3: {
endpoint: string;
key: string;

View File

@ -146,7 +146,7 @@ export function processPainting(painting: string): Buffer | null {
}
}
export async function uploadCDNAsset(key: string, data: Buffer, acl: string): Promise<void> {
export async function uploadCDNAsset(key: string, data: Buffer, acl: string): Promise<boolean> {
const awsPutParams = {
Body: data,
Key: key,
@ -154,7 +154,13 @@ export async function uploadCDNAsset(key: string, data: Buffer, acl: string): Pr
ACL: acl
};
await s3.putObject(awsPutParams).promise();
try {
await s3.putObject(awsPutParams).promise();
return true;
} catch (e) {
console.error(e);
return false;
}
}
export async function getUserFriendPIDs(pid: number): Promise<number[]> {