mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-01-17 07:10:03 +00:00
Some checks are pending
Build / docker-build-otel-collector (push) Waiting to run
Build / docker-build-app (push) Waiting to run
Build / docker-build-copilot (push) Waiting to run
Build / docker-build-e2e (push) Waiting to run
Build / docker-build-admin-dashboard (push) Waiting to run
Build / docker-build-dashboard (push) Waiting to run
Build / docker-build-probe (push) Waiting to run
Build / docker-build-probe-ingest (push) Waiting to run
Build / docker-build-server-monitor-ingest (push) Waiting to run
Build / docker-build-telemetry (push) Waiting to run
Build / docker-build-incoming-request-ingest (push) Waiting to run
Build / docker-build-status-page (push) Waiting to run
Build / docker-build-test-server (push) Waiting to run
Build / docker-build-accounts (push) Waiting to run
Build / docker-build-isolated-vm (push) Waiting to run
Build / docker-build-home (push) Waiting to run
Build / docker-build-worker (push) Waiting to run
Build / docker-build-workflow (push) Waiting to run
Build / docker-build-api-reference (push) Waiting to run
Build / docker-build-docs (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Common Jobs / helm-lint (push) Waiting to run
Common Jobs / js-lint (push) Waiting to run
Compile / compile-accounts (push) Waiting to run
Compile / compile-isolated-vm (push) Waiting to run
Compile / compile-common (push) Waiting to run
Compile / compile-app (push) Waiting to run
Compile / compile-home (push) Waiting to run
Compile / compile-worker (push) Waiting to run
Compile / compile-workflow (push) Waiting to run
Compile / compile-api-reference (push) Waiting to run
Compile / compile-docs-reference (push) Waiting to run
Compile / compile-copilot (push) Waiting to run
Compile / compile-nginx (push) Waiting to run
Compile / compile-infrastructure-agent (push) Waiting to run
Compile / compile-admin-dashboard (push) Waiting to run
Compile / compile-dashboard (push) Waiting to run
Compile / compile-e2e (push) Waiting to run
Compile / compile-probe (push) Waiting to run
Compile / compile-probe-ingest (push) Waiting to run
Compile / compile-server-monitor-ingest (push) Waiting to run
Compile / compile-telemetry (push) Waiting to run
Compile / compile-incoming-request-ingest (push) Waiting to run
Compile / compile-status-page (push) Waiting to run
Compile / compile-test-server (push) Waiting to run
Compile / compile-mcp (push) Waiting to run
OpenAPI Spec Generation / generate-openapi-spec (push) Waiting to run
OneUptime Reliability Copilot / Analyze Code (push) Waiting to run
Terraform Provider Generation / generate-terraform-provider (push) Waiting to run
Common Test / test (push) Waiting to run
Incoming Request Ingest Test / test (push) Waiting to run
MCP Server Test / test (push) Waiting to run
ProbeIngest Test / test (push) Waiting to run
Probe Test / test (push) Waiting to run
Telemetry Test / test (push) Waiting to run
Tests / test-app (push) Waiting to run
Tests / test-home (push) Waiting to run
Tests / test-worker (push) Waiting to run
96 lines
2.8 KiB
TypeScript
96 lines
2.8 KiB
TypeScript
import IncidentInternalNote from "../../Models/DatabaseModels/IncidentInternalNote";
|
|
import File from "../../Models/DatabaseModels/File";
|
|
import NotFoundException from "../../Types/Exception/NotFoundException";
|
|
import ObjectID from "../../Types/ObjectID";
|
|
import IncidentInternalNoteService, {
|
|
Service as IncidentInternalNoteServiceType,
|
|
} from "../Services/IncidentInternalNoteService";
|
|
import Response from "../Utils/Response";
|
|
import BaseAPI from "./BaseAPI";
|
|
import UserMiddleware from "../Middleware/UserAuthorization";
|
|
import CommonAPI from "./CommonAPI";
|
|
import DatabaseCommonInteractionProps from "../../Types/BaseDatabase/DatabaseCommonInteractionProps";
|
|
import {
|
|
ExpressRequest,
|
|
ExpressResponse,
|
|
NextFunction,
|
|
} from "../Utils/Express";
|
|
|
|
export default class IncidentInternalNoteAPI extends BaseAPI<
|
|
IncidentInternalNote,
|
|
IncidentInternalNoteServiceType
|
|
> {
|
|
public constructor() {
|
|
super(IncidentInternalNote, IncidentInternalNoteService);
|
|
|
|
this.router.get(
|
|
`${new this.entityType().getCrudApiPath()?.toString()}/attachment/:projectId/:noteId/:fileId`,
|
|
UserMiddleware.getUserMiddleware,
|
|
async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
|
|
try {
|
|
await this.getAttachment(req, res);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
private async getAttachment(
|
|
req: ExpressRequest,
|
|
res: ExpressResponse,
|
|
): Promise<void> {
|
|
const noteIdParam: string | undefined = req.params["noteId"];
|
|
const fileIdParam: string | undefined = req.params["fileId"];
|
|
|
|
if (!noteIdParam || !fileIdParam) {
|
|
throw new NotFoundException("Attachment not found");
|
|
}
|
|
|
|
let noteId: ObjectID;
|
|
let fileId: ObjectID;
|
|
|
|
try {
|
|
noteId = new ObjectID(noteIdParam);
|
|
fileId = new ObjectID(fileIdParam);
|
|
} catch {
|
|
throw new NotFoundException("Attachment not found");
|
|
}
|
|
|
|
const props: DatabaseCommonInteractionProps =
|
|
await CommonAPI.getDatabaseCommonInteractionProps(req);
|
|
|
|
const note: IncidentInternalNote | null = await this.service.findOneBy({
|
|
query: {
|
|
_id: noteId,
|
|
},
|
|
select: {
|
|
attachments: {
|
|
_id: true,
|
|
file: true,
|
|
fileType: true,
|
|
name: true,
|
|
},
|
|
},
|
|
props,
|
|
});
|
|
|
|
const attachment: File | undefined = note?.attachments?.find(
|
|
(file: File) => {
|
|
const attachmentId: string | null = file._id
|
|
? file._id.toString()
|
|
: file.id
|
|
? file.id.toString()
|
|
: null;
|
|
return attachmentId === fileId.toString();
|
|
},
|
|
);
|
|
|
|
if (!attachment || !attachment.file) {
|
|
throw new NotFoundException("Attachment not found");
|
|
}
|
|
|
|
Response.setNoCacheHeaders(res);
|
|
return Response.sendFileResponse(req, res, attachment);
|
|
}
|
|
}
|