Skip to content

Commit

Permalink
do not slugify tags so any locale can be used
Browse files Browse the repository at this point in the history
  • Loading branch information
tdjsnelling committed Mar 14, 2023
1 parent 0fef96b commit 0cb5368
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions api/src/controllers/torrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import Comment from "../schema/comment";
import Group from "../schema/group";
import { createGroup, addToGroup, removeFromGroup } from "./group";

const urlReservedCharRegex = /[&$+,/:;=?@#<>\[\]{}|\\\^%]/g;

const formatTag = (tag) =>
tag
.trim()
.toLowerCase()
.replaceAll(urlReservedCharRegex, "")
.replaceAll(" ", "-");

export const embellishTorrentsWithTrackerScrape = async (tracker, torrents) => {
if (!torrents.length) return [];

Expand Down Expand Up @@ -127,9 +136,7 @@ export const uploadTorrent = async (req, res, next) => {
upvotes: [],
downvotes: [],
freeleech: false,
tags: (req.body.tags ?? "")
.split(",")
.map((t) => slugify(t.trim(), { lower: true })),
tags: (req.body.tags ?? "").split(",").map((t) => formatTag(t)),
group: groupId,
mediaInfo: req.body.mediaInfo,
});
Expand Down Expand Up @@ -200,9 +207,7 @@ export const editTorrent = async (req, res, next) => {
type: req.body.type,
source: req.body.source,
description: req.body.description,
tags: (req.body.tags ?? "")
.split(",")
.map((t) => slugify(t.trim(), { lower: true })),
tags: (req.body.tags ?? "").split(",").map((t) => formatTag(t)),
},
mediaInfo: req.body.mediaInfo,
}
Expand Down Expand Up @@ -684,7 +689,7 @@ export const searchTorrents = (tracker) => async (req, res, next) => {
query: query ? decodeURIComponent(query) : undefined,
category,
source,
tag,
tag: tag ? decodeURIComponent(tag) : undefined,
userId: req.userId,
tracker,
});
Expand Down

0 comments on commit 0cb5368

Please sign in to comment.