commit
a21774d589
@ -65,7 +65,7 @@ CUSTOM_DOMAIN_USE_HTTPS=false
|
||||
# More info on the configuration on http://nodemailer.com/.
|
||||
MAIL_ENABLED=false
|
||||
MAIL_HOST=
|
||||
MAIL_PORT=
|
||||
MAIL_PORT=587
|
||||
MAIL_SECURE=true
|
||||
MAIL_USER=
|
||||
MAIL_FROM=
|
||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "kutt",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kutt",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bcryptjs": "2.4.3",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kutt",
|
||||
"version": "3.1.0",
|
||||
"version": "3.1.1",
|
||||
"description": "Modern URL shortener.",
|
||||
"main": "./server/server.js",
|
||||
"scripts": {
|
||||
|
@ -15,6 +15,11 @@ if (process.env.LINK_CUSTOM_ALPHABET === "") {
|
||||
delete process.env.LINK_CUSTOM_ALPHABET;
|
||||
}
|
||||
|
||||
// make sure jwt secret is not empty
|
||||
if (process.env.JWT_SECRET === "") {
|
||||
delete process.env.JWT_SECRET;
|
||||
}
|
||||
|
||||
const env = cleanEnv(process.env, {
|
||||
PORT: num({ default: 3000 }),
|
||||
SITE_NAME: str({ example: "Kutt", default: "Kutt" }),
|
||||
|
@ -28,4 +28,6 @@ db.isPostgres = isPostgres;
|
||||
db.isSQLite = isSQLite;
|
||||
db.isMySQL = isMySQL;
|
||||
|
||||
db.compatibleILIKE = isPostgres ? "andWhereILike" : "andWhereLike";
|
||||
|
||||
module.exports = db;
|
||||
|
@ -142,16 +142,16 @@ async function getAdmin(match, params) {
|
||||
if (params?.user) {
|
||||
const id = parseInt(params?.user);
|
||||
if (Number.isNaN(id)) {
|
||||
query.andWhereILike("users.email", "%" + params.user + "%");
|
||||
query[knex.compatibleILIKE]("users.email", "%" + params.user + "%");
|
||||
} else {
|
||||
query.andWhere("domains.user_id", id);
|
||||
}
|
||||
}
|
||||
|
||||
if (params?.search) {
|
||||
query.andWhereRaw(
|
||||
"concat_ws(' ', domains.address, domains.homepage) ILIKE '%' || ? || '%'",
|
||||
[params.search]
|
||||
query[knex.compatibleILIKE](
|
||||
knex.raw("concat_ws(' ', domains.address, domains.homepage)"),
|
||||
"%" + params.search + "%"
|
||||
);
|
||||
}
|
||||
|
||||
@ -160,7 +160,7 @@ async function getAdmin(match, params) {
|
||||
}
|
||||
|
||||
query.leftJoin(
|
||||
knex("links").select("domain_id").count("id as links_count").groupBy("domain_id").as("l"),
|
||||
knex("links").select("domain_id").count("* as links_count").groupBy("domain_id").as("l"),
|
||||
"domains.id",
|
||||
"l.domain_id"
|
||||
);
|
||||
@ -180,19 +180,22 @@ async function totalAdmin(match, params) {
|
||||
if (params?.user) {
|
||||
const id = parseInt(params?.user);
|
||||
if (Number.isNaN(id)) {
|
||||
query.andWhereILike("users.email", "%" + params.user + "%");
|
||||
query[knex.compatibleILIKE]("users.email", "%" + params.user + "%");
|
||||
} else {
|
||||
query.andWhere("domains.user_id", id);
|
||||
}
|
||||
}
|
||||
|
||||
if (params?.search) {
|
||||
query.andWhereILike("domains.address", "%" + params.search + "%");
|
||||
query[knex.compatibleILIKE](
|
||||
knex.raw("concat_ws(' ', domains.address, domains.homepage)"),
|
||||
"%" + params.search + "%"
|
||||
);
|
||||
}
|
||||
|
||||
if (params?.links !== undefined) {
|
||||
query.leftJoin(
|
||||
knex("links").select("domain_id").count("id as links_count").groupBy("domain_id").as("l"),
|
||||
knex("links").select("domain_id").count("* as links_count").groupBy("domain_id").as("l"),
|
||||
"domains.id",
|
||||
"l.domain_id"
|
||||
);
|
||||
@ -200,7 +203,7 @@ async function totalAdmin(match, params) {
|
||||
}
|
||||
|
||||
query.leftJoin("users", "domains.user_id", "users.id");
|
||||
query.count("domains.id as count");
|
||||
query.count("* as count");
|
||||
|
||||
const [{ count }] = await query;
|
||||
|
||||
|
@ -64,13 +64,13 @@ async function total(match, params) {
|
||||
});
|
||||
|
||||
if (params?.search) {
|
||||
query.andWhereRaw(
|
||||
"concat_ws(' ', description, links.address, target, domains.address) ILIKE '%' || ? || '%'",
|
||||
[params.search]
|
||||
query[knex.compatibleILIKE](
|
||||
knex.raw("concat_ws(' ', description, links.address, target, domains.address)"),
|
||||
"%" + params.search + "%"
|
||||
);
|
||||
}
|
||||
query.leftJoin("domains", "links.domain_id", "domains.id");
|
||||
query.count("links.id as count");
|
||||
query.count("* as count");
|
||||
|
||||
const [{ count }] = await query;
|
||||
|
||||
@ -87,26 +87,26 @@ async function totalAdmin(match, params) {
|
||||
if (params?.user) {
|
||||
const id = parseInt(params?.user);
|
||||
if (Number.isNaN(id)) {
|
||||
query.andWhereILike("users.email", "%" + params.user + "%");
|
||||
query[knex.compatibleILIKE]("users.email", "%" + params.user + "%");
|
||||
} else {
|
||||
query.andWhere("links.user_id", params.user);
|
||||
}
|
||||
}
|
||||
|
||||
if (params?.search) {
|
||||
query.andWhereRaw(
|
||||
"concat_ws(' ', description, links.address, target) ILIKE '%' || ? || '%'",
|
||||
[params.search]
|
||||
query[knex.compatibleILIKE](
|
||||
knex.raw("concat_ws(' ', description, links.address, target)"),
|
||||
"%" + params.search + "%"
|
||||
);
|
||||
}
|
||||
|
||||
if (params?.domain) {
|
||||
query.andWhereRaw("domains.address ILIKE '%' || ? || '%'", [params.domain]);
|
||||
query[knex.compatibleILIKE]("domains.address", "%" + params.domain + "%");
|
||||
}
|
||||
|
||||
query.leftJoin("domains", "links.domain_id", "domains.id");
|
||||
query.leftJoin("users", "links.user_id", "users.id");
|
||||
query.count("links.id as count");
|
||||
query.count("* as count");
|
||||
|
||||
const [{ count }] = await query;
|
||||
|
||||
@ -122,9 +122,9 @@ async function get(match, params) {
|
||||
.orderBy("links.id", "desc");
|
||||
|
||||
if (params?.search) {
|
||||
query.andWhereRaw(
|
||||
"concat_ws(' ', description, links.address, target, domains.address) ILIKE '%' || ? || '%'",
|
||||
[params.search]
|
||||
query[knex.compatibleILIKE](
|
||||
knex.raw("concat_ws(' ', description, links.address, target, domains.address)"),
|
||||
"%" + params.search + "%"
|
||||
);
|
||||
}
|
||||
|
||||
@ -148,21 +148,21 @@ async function getAdmin(match, params) {
|
||||
if (params?.user) {
|
||||
const id = parseInt(params?.user);
|
||||
if (Number.isNaN(id)) {
|
||||
query.andWhereILike("users.email", "%" + params.user + "%");
|
||||
query[knex.compatibleILIKE]("users.email", "%" + params.user + "%");
|
||||
} else {
|
||||
query.andWhere("links.user_id", params.user);
|
||||
}
|
||||
}
|
||||
|
||||
if (params?.search) {
|
||||
query.andWhereRaw(
|
||||
"concat_ws(' ', description, links.address, target) ILIKE '%' || ? || '%'",
|
||||
[params.search]
|
||||
query[knex.compatibleILIKE](
|
||||
knex.raw("concat_ws(' ', description, links.address, target)"),
|
||||
"%" + params.search + "%"
|
||||
);
|
||||
}
|
||||
|
||||
if (params?.domain) {
|
||||
query.andWhereRaw("domains.address ILIKE '%' || ? || '%'", [params.domain]);
|
||||
query[knex.compatibleILIKE]("domains.address", "%" + params.domain + "%");
|
||||
}
|
||||
|
||||
query.leftJoin("domains", "links.domain_id", "domains.id");
|
||||
|
@ -144,7 +144,7 @@ async function getAdmin(match, params) {
|
||||
if (params?.search) {
|
||||
const id = parseInt(params?.search);
|
||||
if (Number.isNaN(id)) {
|
||||
query.andWhereILike("users.email", "%" + params?.search + "%");
|
||||
query[knex.compatibleILIKE]("users.email", "%" + params?.search + "%");
|
||||
} else {
|
||||
query.andWhere("users.id", params?.search);
|
||||
}
|
||||
@ -169,7 +169,7 @@ async function getAdmin(match, params) {
|
||||
"d.user_id"
|
||||
)
|
||||
query.leftJoin(
|
||||
knex("links").select("user_id").count("id as links_count").groupBy("user_id").as("l"),
|
||||
knex("links").select("user_id").count("* as links_count").groupBy("user_id").as("l"),
|
||||
"users.id",
|
||||
"l.user_id"
|
||||
);
|
||||
@ -179,14 +179,14 @@ async function getAdmin(match, params) {
|
||||
|
||||
async function totalAdmin(match, params) {
|
||||
const query = knex("users")
|
||||
.count("users.id as count")
|
||||
.count("* as count")
|
||||
.fromRaw('users')
|
||||
.where(normalizeMatch(match));
|
||||
|
||||
if (params?.search) {
|
||||
const id = parseInt(params?.search);
|
||||
if (Number.isNaN(id)) {
|
||||
query.andWhereILike("users.email", "%" + params?.search + "%");
|
||||
query[knex.compatibleILIKE]("users.email", "%" + params?.search + "%");
|
||||
} else {
|
||||
query.andWhere("users.id", params?.search);
|
||||
}
|
||||
@ -209,13 +209,13 @@ async function totalAdmin(match, params) {
|
||||
if (params?.links !== undefined) {
|
||||
query.andWhere("links", params?.links ? "is not" : "is", null);
|
||||
query.leftJoin(
|
||||
knex("links").select("user_id").count("id as links").groupBy("user_id").as("l"),
|
||||
knex("links").select("user_id").count("* as links").groupBy("user_id").as("l"),
|
||||
"users.id",
|
||||
"l.user_id"
|
||||
);
|
||||
}
|
||||
|
||||
const [{count}] = await query;
|
||||
const [{ count }] = await query;
|
||||
|
||||
return typeof count === "number" ? count : parseInt(count);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user