Skip to content

Commit

Permalink
new update gogogogo!
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMario211 committed Nov 8, 2024
1 parent 35e4446 commit 5f57934
Show file tree
Hide file tree
Showing 56 changed files with 1,914 additions and 584 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ file(GLOB SOURCES
src/nodes/*.cpp
src/ui/*.cpp
src/ui/popups/*.cpp
src/ui/admin/*.cpp
src/ui/auth/*.cpp
)

Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.4.0
- Allowed clicking on users profiles in comments (will only work for players that authenticated with Object Workshop before)
- Added \n for descriptions and comments
- Changed clicking on usernames in comments to redirect to the users objects rather than profile
- Allowed symbols in object names
- Changed descriptions (mainly editing) to use RobTop's textarea (like comments)
- Fixed bug where selecting an object in the workshop will not allow you to select in the editor unless you re-enter
- Added warnings
# v1.3.1
- Fixed bug where going to a users profile while on another page will assume you want to go to that page
# v1.3.0
Expand Down
9 changes: 7 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"geode": "3.7.1",
"geode": "3.9.0",
"gd": {
"win": "2.206",
"android": "2.206",
Expand All @@ -8,7 +8,7 @@
},
"id": "firee.object-workshop",
"name": "Object Workshop",
"version": "v1.3.1",
"version": "v1.4.0",
"developer": "Firee",
"description": "Download, upload, or find custom objects made by other creators!",
"resources": {
Expand Down Expand Up @@ -61,6 +61,11 @@
"id": "alphalaneous.editortab_api",
"version": ">=v1.0.0",
"importance": "required"
},
{
"id": "geode.node-ids",
"version": ">=1.14.1",
"importance": "required"
}
]
}
Binary file added resources/blueButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/profileObjBtn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions server/src/Components/Case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default interface CaseData {
id: number;
case_type: number;
account_id: number;
staff_account_id: number;
reason: string;
timestamp: Date | number;
expiration: Date | number;
ack: boolean;
ack_timestamp: Date | number;
};
50 changes: 32 additions & 18 deletions server/src/controllers/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import ObjectData from '@/Components/Object';
import { getCache } from '../postgres';
import { Router, Request, Response } from 'express'
import { query, body, param, validationResult, CustomValidator } from 'express-validator';
import { verifyToken } from './user';
import { verifyToken, banCheck } from './user';
import axios from 'axios';
import moment from 'moment'
import { UserData } from '@/Components/User';

const allowedTags = ["Font", "Decoration", "Gameplay", "Art", "Structure", "Custom", "Icon", "Meme", "Technical", "Particles", "Triggers", "SFX", "Effects", "Auto Build"];
const allowedTags = ["Font", "Decoration", "Gameplay", "Art", "Structure", "Custom", "Icon", "Meme", "Technical", "Particles", "Triggers", "SFX", "Effects", "Auto Build", "Recreation"];

const oRouter = Router();

Expand Down Expand Up @@ -138,7 +138,7 @@ oRouter.post('/objects/upload',
const { token, name, description, data } = req.body;
let tags = req.body.tags as Array<string>;
if (name.length > 64) return res.status(413).json({error: "The name cannot be more than 64 characters long!"});
if (description.length > 300) return res.status(413).json({error: "The description cannot be more than 300 characters long!"});
if (description.length > 500) return res.status(413).json({error: "The description cannot be more than 500 characters long!"});
const splitData: Array<string> = data.split(";");
if (splitData.length > 50000) return res.status(413).json({error: "You cannot upload a custom object with more than 50,000 objects!"})
const hasBlacklistedIDs = splitData.find(objStr => {
Expand All @@ -164,7 +164,7 @@ oRouter.post('/objects/upload',
return res.status(401).json({ error: verifyRes.message });
}
if (!verifyRes.user) return res.status(404).json({error: "Couldn't retrieve user."});
if (verifyRes.user.role == -1) return res.status(403).json({error: "You are banned! Reason: " + verifyRes.user.ban_reason});
if (banCheck(res, verifyRes.user, 1)) return;
try {
const dupCheck = await pool.query("SELECT id FROM objects WHERE data = $1 LIMIT 1;", [data]);
if (dupCheck.rowCount != null && dupCheck.rowCount > 0) return res.status(409).json({error: "You cannot upload an object that already exists!"});
Expand Down Expand Up @@ -243,13 +243,13 @@ oRouter.post('/objects/:id/overwrite',
return res.status(401).json({ error: verifyRes.message });
}
if (!verifyRes.user) return res.status(404).json({error: "Couldn't retrieve user."});
if (verifyRes.user.role == -1) return res.status(403).json({error: "You are banned! Reason: " + verifyRes.user.ban_reason});
if (banCheck(res, verifyRes.user, 1)) return;
try {
const query = await pool.query("SELECT * FROM objects WHERE id = $1 AND status != 3", [objectID])
if (!query.rows.length) return res.status(404).json({error: "Object not found."});
const objData: ObjectData = query.rows[0];
if (objData.account_id != verifyRes.user.account_id) return res.status(403).json({error: "This is not your object!"});
if (verifyRes.user.role == 0) {
if (verifyRes.user.role == 0 && !objData.featured) {
await pool.query("UPDATE objects SET data = $1, status = 0, updated_at = $2, version = version + 1 WHERE id = $3", [data, new Date(), objectID]);
} else {
await pool.query("UPDATE objects SET data = $1, updated_at = $2, version = version + 1 WHERE id = $3", [data, new Date(), objectID]);
Expand Down Expand Up @@ -333,7 +333,8 @@ oRouter.post('/objects/:id/rate',
return res.status(401).json({ error: verifyRes.message });
}
const accountID = verifyRes.user?.account_id;
if (verifyRes.user?.role == -1) return res.status(403).json({error: "You are banned! Reason: " + verifyRes.user.ban_reason});
if (!verifyRes.user) return;
if (banCheck(res, verifyRes.user, 3)) return;
try {
const objExists = await pool.query("SELECT EXISTS (SELECT 1 FROM objects WHERE id = $1 AND status = 1)", [objectID])
if (!objExists.rows[0].exists) return res.status(404).json({error: "Object not found."});
Expand Down Expand Up @@ -377,8 +378,9 @@ oRouter.post('/objects/:id/comment',
} else if (!verifyRes.valid) {
return res.status(401).json({ error: verifyRes.message });
}
const accountID = verifyRes.user?.account_id;
if (verifyRes.user?.role == -1) return res.status(403).json({error: "You are banned! Reason: " + verifyRes.user.ban_reason});
if (!verifyRes.user) return;
const accountID = verifyRes.user.account_id;
if (banCheck(res, verifyRes.user, 2)) return;
try {
const objExists = await pool.query("SELECT EXISTS (SELECT 1 FROM objects WHERE id = $1 AND status = 1)", [objectID])
if (!objExists.rows[0].exists) return res.status(404).json({error: "Object not found."});
Expand Down Expand Up @@ -415,8 +417,9 @@ oRouter.post('/objects/:id/comments/:commentid/pin',
} else if (!verifyRes.valid) {
return res.status(401).json({ error: verifyRes.message });
}
const accountID = verifyRes.user?.account_id;
if (verifyRes.user?.role == -1) return res.status(403).json({error: "You are banned! Reason: " + verifyRes.user.ban_reason});
if (!verifyRes.user) return;
const accountID = verifyRes.user.account_id;
if (banCheck(res, verifyRes.user, 3)) return;
try {
if (verifyRes.user && verifyRes.user.role == 3) {
const objExists = await pool.query("SELECT EXISTS (SELECT 1 FROM objects WHERE id = $1)", [objectID])
Expand Down Expand Up @@ -520,8 +523,9 @@ oRouter.post('/objects/:id/comments/:commentid/delete',
} else if (!verifyRes.valid) {
return res.status(401).json({ error: verifyRes.message });
}
if (!verifyRes.user) return;
const accountID = verifyRes.user?.account_id;
if (verifyRes.user?.role == -1) return res.status(403).json({error: "You are banned! Reason: " + verifyRes.user.ban_reason});
if (banCheck(res, verifyRes.user, 3)) return;
try {
const query = await pool.query("SELECT * FROM objects WHERE id = $1 AND status = 1", [objectID])
if (!query.rows.length) return res.status(404).json({error: "Object not found."});
Expand Down Expand Up @@ -567,8 +571,9 @@ oRouter.post('/objects/:id/report',
} else if (!verifyRes.valid) {
return res.status(401).json({ error: verifyRes.message });
}
const accountID = verifyRes.user?.account_id;
if (verifyRes.user?.role == -1) return res.status(403).json({error: "You are banned! Reason: " + verifyRes.user.ban_reason});
if (!verifyRes.user) return;
const accountID = verifyRes.user.account_id;
if (banCheck(res, verifyRes.user, 1)) return;
try {
const objExists = await pool.query("SELECT EXISTS (SELECT 1 FROM objects WHERE id = $1 AND status = 1)", [objectID])
if (!objExists.rows[0].exists) return res.status(404).json({error: "Object not found."});
Expand Down Expand Up @@ -736,7 +741,7 @@ oRouter.post('/objects/:id/update',
const { token, name, description } = req.body;
let tags = req.body.tags as Array<string>;
if (name.length > 64) return res.status(413).json({error: "The name cannot be more than 64 characters long!"});
if (description.length > 300) return res.status(413).json({error: "The description cannot be more than 300 characters long!"});
if (description.length > 500) return res.status(413).json({error: "The description cannot be more than 500 characters long!"});
if (!tags || !tags.length) tags = [];
if (tags.length > 5) return res.status(413).json({error: "You can only add a maximum of 5 tags!"});
getCache().then(pool => { // returns a PoolClient
Expand Down Expand Up @@ -1219,7 +1224,7 @@ oRouter.post('/objects/reports',
} else if (!verifyRes.valid) {
return res.status(401).json({ error: verifyRes.message });
}
if (verifyRes.user && verifyRes.user.role != 3) return res.status(403).json({ error: "No permission" });
if (verifyRes.user && verifyRes.user.role < 2) return res.status(403).json({ error: "No permission" });
const page = parseInt(req.query.page as string) || 1;
const limit = 9;
const offset = (page - 1) * limit;
Expand All @@ -1231,7 +1236,12 @@ oRouter.post('/objects/reports',
COALESCE(AVG(orate.stars), 0) as rating,
COUNT(orate.stars) as rating_count,
COUNT(*) OVER() AS total_records,
COUNT(rep) AS report_count
COUNT(rep) AS report_count,
COALESCE(ARRAY_AGG(DISTINCT jsonb_build_object(
'reason', rep.reason,
'account_id', rep.account_id,
'timestamp', rep.timestamp
)) FILTER (WHERE rep.object_id IS NOT NULL), '{}') AS reports
FROM
objects o
LEFT JOIN
Expand All @@ -1248,7 +1258,11 @@ oRouter.post('/objects/reports',
const totalRecords = (result.rows.length > 0) ? parseInt(result.rows[0].total_records) : 0;
const totalPages = Math.ceil(totalRecords / limit);

const objectData = convertRowsToObjects(result.rows)
const objectData = (convertRowsToObjects(result.rows) as Array<any>).map((value, index) => {
value.report_count = parseInt(result.rows[index].report_count);
value.reports = result.rows[index].reports;
return value;
});
res.json({
results: objectData,
page,
Expand Down
Loading

0 comments on commit 5f57934

Please sign in to comment.