mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-23 10:27:28 -07:00
Compare commits
No commits in common. "3804b66d1d355801da44dfa9847df0655fce8cfc" and "ebe2ff0e215b76aa64ad17c4567eb970698e8d75" have entirely different histories.
3804b66d1d
...
ebe2ff0e21
6 changed files with 12 additions and 68 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "iceshrimp",
|
"name": "iceshrimp",
|
||||||
"version": "2023.12.9-jormungandr.23.1",
|
"version": "2023.12.9-jormungandr.23",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://iceshrimp.dev/limepotato/jormungandr-bite.git"
|
"url": "https://iceshrimp.dev/limepotato/jormungandr-bite.git"
|
||||||
|
|
|
@ -8,8 +8,10 @@ import type { IPoll } from "@/models/entities/poll.js";
|
||||||
|
|
||||||
export async function extractPollFromQuestion(
|
export async function extractPollFromQuestion(
|
||||||
source: string | IObject,
|
source: string | IObject,
|
||||||
resolver: Resolver,
|
resolver?: Resolver,
|
||||||
): Promise<IPoll> {
|
): Promise<IPoll> {
|
||||||
|
if (resolver == null) resolver = new Resolver();
|
||||||
|
|
||||||
const question = await resolver.resolve(source);
|
const question = await resolver.resolve(source);
|
||||||
|
|
||||||
if (!isQuestion(question)) {
|
if (!isQuestion(question)) {
|
||||||
|
@ -50,7 +52,7 @@ export async function extractPollFromQuestion(
|
||||||
*/
|
*/
|
||||||
export async function updateQuestion(
|
export async function updateQuestion(
|
||||||
value: string | IQuestion,
|
value: string | IQuestion,
|
||||||
resolver: Resolver,
|
resolver?: Resolver,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const uri = typeof value === "string" ? value : getApId(value);
|
const uri = typeof value === "string" ? value : getApId(value);
|
||||||
|
|
||||||
|
@ -66,7 +68,8 @@ export async function updateQuestion(
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
// resolve new Question object
|
// resolve new Question object
|
||||||
const question = (await resolver.resolve(value)) as IQuestion;
|
const _resolver = resolver ?? new Resolver();
|
||||||
|
const question = (await _resolver.resolve(value)) as IQuestion;
|
||||||
apLogger.debug(`fetched question: ${JSON.stringify(question, null, 2)}`);
|
apLogger.debug(`fetched question: ${JSON.stringify(question, null, 2)}`);
|
||||||
|
|
||||||
if (question.type !== "Question") throw new Error("object is not a Question");
|
if (question.type !== "Question") throw new Error("object is not a Question");
|
||||||
|
|
|
@ -104,8 +104,6 @@ async function fetchAny(
|
||||||
if (await shouldBlockInstance(extractDbHost(uri))) return null;
|
if (await shouldBlockInstance(extractDbHost(uri))) return null;
|
||||||
|
|
||||||
const dbResolver = new DbResolver();
|
const dbResolver = new DbResolver();
|
||||||
const resolver = new Resolver();
|
|
||||||
resolver.setUser(me);
|
|
||||||
|
|
||||||
const [user, note] = await Promise.all([
|
const [user, note] = await Promise.all([
|
||||||
dbResolver.getUserFromApId(uri),
|
dbResolver.getUserFromApId(uri),
|
||||||
|
@ -117,7 +115,7 @@ async function fetchAny(
|
||||||
// Update questions if the stored (remote) note contains the poll
|
// Update questions if the stored (remote) note contains the poll
|
||||||
const key = `pollFetched:${note.uri}`;
|
const key = `pollFetched:${note.uri}`;
|
||||||
if ((await redisClient.exists(key)) === 0) {
|
if ((await redisClient.exists(key)) === 0) {
|
||||||
if (await updateQuestion(note.uri, resolver)) {
|
if (await updateQuestion(note.uri)) {
|
||||||
local.object.poll = await populatePoll(note, me?.id ?? null);
|
local.object.poll = await populatePoll(note, me?.id ?? null);
|
||||||
}
|
}
|
||||||
// Allow fetching the poll again after 1 minute
|
// Allow fetching the poll again after 1 minute
|
||||||
|
@ -128,6 +126,8 @@ async function fetchAny(
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetching Object once from remote
|
// fetching Object once from remote
|
||||||
|
const resolver = new Resolver();
|
||||||
|
resolver.setUser(me);
|
||||||
const object = await resolver.resolve(uri);
|
const object = await resolver.resolve(uri);
|
||||||
|
|
||||||
// /@user If a URI other than the id is specified,
|
// /@user If a URI other than the id is specified,
|
||||||
|
|
|
@ -14,10 +14,7 @@ import { detectType } from "@/misc/get-file-info.js";
|
||||||
import { convertToWebp } from "@/services/drive/image-processor.js";
|
import { convertToWebp } from "@/services/drive/image-processor.js";
|
||||||
import { GenerateVideoThumbnail } from "@/services/drive/generate-video-thumbnail.js";
|
import { GenerateVideoThumbnail } from "@/services/drive/generate-video-thumbnail.js";
|
||||||
import { StatusError } from "@/misc/fetch.js";
|
import { StatusError } from "@/misc/fetch.js";
|
||||||
import { FILE_TYPE_BROWSERSAFE, MINUTE } from "@/const.js";
|
import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
|
||||||
import { IEndpointMeta } from "@/server/api/endpoints.js";
|
|
||||||
import { getIpHash } from "@/misc/get-ip-hash.js";
|
|
||||||
import { limiter } from "@/server/api/limiter.js";
|
|
||||||
|
|
||||||
const _filename = fileURLToPath(import.meta.url);
|
const _filename = fileURLToPath(import.meta.url);
|
||||||
const _dirname = dirname(_filename);
|
const _dirname = dirname(_filename);
|
||||||
|
@ -34,31 +31,6 @@ const commonReadableHandlerGenerator =
|
||||||
export default async function (ctx: Koa.Context) {
|
export default async function (ctx: Koa.Context) {
|
||||||
const key = ctx.params.key;
|
const key = ctx.params.key;
|
||||||
|
|
||||||
// koa will automatically load the `X-Forwarded-For` header if `proxy: true` is configured in the app.
|
|
||||||
let limitActor: string;
|
|
||||||
limitActor = getIpHash(ctx.ip);
|
|
||||||
|
|
||||||
const limit: IEndpointMeta["limit"] = {
|
|
||||||
key: `drive-file:${key}`,
|
|
||||||
duration: MINUTE * 10,
|
|
||||||
max: 10
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rate limit
|
|
||||||
await limiter(
|
|
||||||
limit as IEndpointMeta["limit"] & { key: NonNullable<string> },
|
|
||||||
limitActor,
|
|
||||||
).catch((e) => {
|
|
||||||
const remainingTime = e.remainingTime
|
|
||||||
? `Please try again in ${e.remainingTime}.`
|
|
||||||
: "Please try again later.";
|
|
||||||
|
|
||||||
ctx.status = 429;
|
|
||||||
ctx.body = "Rate limit exceeded. " + remainingTime;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ctx.status == 429) return;
|
|
||||||
|
|
||||||
// Fetch drive file
|
// Fetch drive file
|
||||||
const file = await DriveFiles.createQueryBuilder("file")
|
const file = await DriveFiles.createQueryBuilder("file")
|
||||||
.where("file.accessKey = :accessKey", { accessKey: key })
|
.where("file.accessKey = :accessKey", { accessKey: key })
|
||||||
|
|
|
@ -9,12 +9,9 @@ import { createTemp } from "@/misc/create-temp.js";
|
||||||
import { downloadUrl } from "@/misc/download-url.js";
|
import { downloadUrl } from "@/misc/download-url.js";
|
||||||
import { detectType } from "@/misc/get-file-info.js";
|
import { detectType } from "@/misc/get-file-info.js";
|
||||||
import { StatusError } from "@/misc/fetch.js";
|
import { StatusError } from "@/misc/fetch.js";
|
||||||
import { FILE_TYPE_BROWSERSAFE, MINUTE } from "@/const.js";
|
import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
|
||||||
import { serverLogger } from "../index.js";
|
import { serverLogger } from "../index.js";
|
||||||
import { isMimeImage } from "@/misc/is-mime-image.js";
|
import { isMimeImage } from "@/misc/is-mime-image.js";
|
||||||
import { getIpHash } from "@/misc/get-ip-hash.js";
|
|
||||||
import { limiter } from "@/server/api/limiter.js";
|
|
||||||
import { IEndpointMeta } from "@/server/api/endpoints.js";
|
|
||||||
|
|
||||||
export async function proxyMedia(ctx: Koa.Context) {
|
export async function proxyMedia(ctx: Koa.Context) {
|
||||||
const url = "url" in ctx.query ? ctx.query.url : `https://${ctx.params.url}`;
|
const url = "url" in ctx.query ? ctx.query.url : `https://${ctx.params.url}`;
|
||||||
|
@ -24,33 +21,6 @@ export async function proxyMedia(ctx: Koa.Context) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// koa will automatically load the `X-Forwarded-For` header if `proxy: true` is configured in the app.
|
|
||||||
let limitActor: string;
|
|
||||||
limitActor = getIpHash(ctx.ip);
|
|
||||||
|
|
||||||
const parsedUrl = new URL(url);
|
|
||||||
|
|
||||||
const limit: IEndpointMeta["limit"] = {
|
|
||||||
key: `media-proxy:${parsedUrl.host}:${parsedUrl.pathname}`,
|
|
||||||
duration: MINUTE * 10,
|
|
||||||
max: 10
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rate limit
|
|
||||||
await limiter(
|
|
||||||
limit as IEndpointMeta["limit"] & { key: NonNullable<string> },
|
|
||||||
limitActor,
|
|
||||||
).catch((e) => {
|
|
||||||
const remainingTime = e.remainingTime
|
|
||||||
? `Please try again in ${e.remainingTime}.`
|
|
||||||
: "Please try again later.";
|
|
||||||
|
|
||||||
ctx.status = 429;
|
|
||||||
ctx.body = "Rate limit exceeded. " + remainingTime;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ctx.status == 429) return;
|
|
||||||
|
|
||||||
const { hostname } = new URL(url);
|
const { hostname } = new URL(url);
|
||||||
let resolvedIps;
|
let resolvedIps;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -79,7 +79,6 @@ const showTicker =
|
||||||
justify-self: flex-end;
|
justify-self: flex-end;
|
||||||
border-radius: var(--radius-big);
|
border-radius: var(--radius-big);
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
width: 100%;
|
|
||||||
> .avatar {
|
> .avatar {
|
||||||
width: 3.7em;
|
width: 3.7em;
|
||||||
height: 3.7em;
|
height: 3.7em;
|
||||||
|
|
Loading…
Reference in a new issue