Skip to content
Open
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
41 changes: 33 additions & 8 deletions apps/game/server/lib/http-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fetch, { FormData } from 'node-fetch';
import { config } from '@npwd/config/server';
import { Player } from '../players/player.class';
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { uuidv4 } from '../../utils/fivem';

export async function tweetDiscordPost(url: string, body: string): Promise<any> {
return new Promise((resolve, reject) =>
Expand All @@ -11,16 +13,39 @@ export async function tweetDiscordPost(url: string, body: string): Promise<any>
['Content-Type']: 'application/json',
},
})
.then(async (res) => {
const response: any = await res.json();
resolve(response);
})
.catch((err) => {
reject(err);
})
.then(async (res) => {
const response: any = await res.json();
resolve(response);
})
.catch((err) => {
reject(err);
}),
);
}

export async function r2PhotoUpload(body: string | FormData, token: string): Promise<any> {
return new Promise(async (resolve, reject) => {
const client = new S3Client({
region: "auto",
endpoint: config.images.r2.endpoint,
credentials: {
accessKeyId: config.images.r2.credentials.accessKeyId,
secretAccessKey: config.images.r2.credentials.secretAccessKey
Comment on lines +32 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should not be in the config. We should get these from Convars not exposed to client.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

}
});
const key = `${uuidv4()}.${config.images.imageEncoding}`;
const command = new PutObjectCommand({
Bucket: config.images.r2.bucketName,
Key: key,
Body: body,
ContentType: "image/" + config.images.imageEncoding
});
const response = await client.send(command);
resolve(`${config.images.url}${key}`);
});
}


export async function apiPhotoUpload(body: string | FormData, token: string): Promise<any> {
return new Promise((resolve, reject) =>
fetch(config.images.url, {
Expand Down Expand Up @@ -74,4 +99,4 @@ export async function webhookPhotoUpload(
reject(err);
}),
);
}
}
25 changes: 24 additions & 1 deletion apps/game/server/photo/photo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { config } from '@npwd/config/server';
import { v4 as uuidv4 } from 'uuid';
import { FormData, fileFromSync } from 'node-fetch';
import * as fs from 'fs';
import { apiPhotoUpload, webhookPhotoUpload } from '../lib/http-service';
import { apiPhotoUpload, r2PhotoUpload, webhookPhotoUpload } from '../lib/http-service';

const exp = global.exports;
const path = GetResourcePath('npwd') + '/uploads';
Expand Down Expand Up @@ -51,6 +51,7 @@ class _PhotoService {

const filePath = `${path}/screenshot-${uuidv4()}.${config.images.imageEncoding}`;

// use this in r2
const _data = Buffer.from(data.replace(`data:${type};base64`, ''), 'base64');
fs.writeFileSync(filePath, _data);

Expand Down Expand Up @@ -86,6 +87,28 @@ class _PhotoService {
}

let returnData;

if (config.images.type == 'r2') {
await r2PhotoUpload(_data, this.TOKEN)
.then(async (result) => {
returnData = result;
})
.catch((err) => {
photoLogger.error(
`Failed to upload photo, status code: ${err.statusCode}: ${err.errorText}`,
{
source: reqObj.source,
},
);
return resp({ status: 'error', errorMsg: 'GENERIC_DB_ERROR' });
});

fs.rmSync(filePath);
const identifier = PlayerService.getIdentifier(reqObj.source);
const photo = await this.photoDB.uploadPhoto(identifier, returnData);
return resp({ status: 'ok', data: photo });
}

await apiPhotoUpload(body, this.TOKEN)
.then((result) => {
returnData = result;
Expand Down
8 changes: 5 additions & 3 deletions apps/phone/src/os/apps/hooks/useApps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { SvgIconComponent } from '@mui/icons-material';
import { useTheme } from '@mui/material';
import { useSettingsValue } from '../../../apps/settings/hooks/useSettings';
import { IconSetObject } from '@typings/settings';
import { usePhone } from '@os/phone/hooks';

export const useApps = () => {
const { icons } = useNotifications();
const theme = useTheme();
const curIconSet = useSettingsValue().iconSet.value as IconSetObject;
const { ResourceConfig } = usePhone();

const apps: IApp[] = useMemo(() => {
return APPS.map((app) => {
Expand Down Expand Up @@ -38,7 +40,7 @@ export const useApps = () => {
<NotificationIcon htmlColor={theme.palette.text.primary} fontSize="small" />
),
icon: <Icon />,
isDisabled: app.disable,
isDisabled: !!ResourceConfig?.disabledApps.find((a) => a === app.id),
};
}

Expand All @@ -47,10 +49,10 @@ export const useApps = () => {
notification: icons.find((i) => i.key === app.id),
NotificationIcon,
notificationIcon: <NotificationIcon htmlColor={app.color} fontSize="small" />,
isDisabled: app.disable,
isDisabled: !!ResourceConfig?.disabledApps.find((a) => a === app.id),
};
});
}, [icons, curIconSet, theme]);
}, [icons, curIconSet, theme, ResourceConfig]);

const allApps = useMemo(() => [...apps], [apps]);
const getApp = useCallback(
Expand Down
9 changes: 8 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@
"authorizationHeader": "Authorization",
"authorizationPrefix": "",
"useAuthorization": true,
"returnedDataIndexes": ["url"]
"returnedDataIndexes": ["url"],
"r2": {
"bucketName": "",
"endpoint" : "",
"credentials": {
"accessKeyId": "",
"secretAccessKey": ""
}
},
"imageSafety": {
"filterUnsafeImageUrls": true,
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fx_version("cerulean")
game("gta5")
description("js runtime monkaW")
authors({ "itschip", "erik-sn", "TasoOneAsia", "kidz", "RockySouthpaw", "SamShanks", "c-wide", "mojito" })
version("3.14.4-beta.0")
version("3.15.1-beta.0")
client_scripts({
"dist/game/client/client.js",
"dist/game/client/*.lua",
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
"@octokit/core": "^3.6.0",
"esbuild": "^0.15.15",
"husky": "^7.0.4",
"lodash": "https://github.com/lodash/lodash.git#npm",
"prettier": "^2.8.3",
"pretty-quick": "^3.1.3",
"rollup": "^2.77.2",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-esbuild": "^4.10.2",
"turbo": "^1.11.3",
"lodash": "https://github.com/lodash/lodash.git#npm"
"wrangler": "^3.55.0"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand All @@ -44,5 +45,8 @@
"pre-commit": "npx run format:staged"
}
},
"dependencies": {}
"dependencies": {
"@aws-sdk/client-s3": "^3.574.0",
"aws-sdk": "^2.1618.0"
}
}
Comment on lines +48 to 52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please install these the correct package.json file. We are using turborepo, so you can install these deps in the game package like this

pnpm --filter @npwd/game add .... from the root dir.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Loading