This commit is contained in:
echo committed 2025-06-24 21:36:56 +02:00
1 parent 02f97c8dfa
commit 06ffc05e2b
9 files changed
+257 -186

No files matched your search

+3 -2
View File
@@ -4,10 +4,11 @@
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="postgresql://root:admin@localhost:5432/imk?schema=public"
DATABASE_URL="postgresql://root:irina76@localhost:5432/imk?schema=public"
JWT_SECRET=some-secret
AWS_REGION=EU2
AWS_ACCESS_KEY_ID=4d2f5655369a02100375e3247d7e1fe6
AWS_SECRET_ACCESS_KEY=6d4723e14c0d799b89948c24dbe983e4
AWS_S3_BUCKET_NAME=imk-data
AWS_ENDPOINT_URL=https://eu2.contabostorage.com
AWS_ENDPOINT_URL=https://eu2.contabostorage.com
+82
View File
@@ -0,0 +1,82 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var client_1 = require("@prisma/client");
var bcrypt = require("bcrypt");
var prisma = new client_1.PrismaClient();
function main() {
return __awaiter(this, void 0, void 0, function () {
var hashedPassword, admin;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, bcrypt.hash('admin123', 10)];
case 1:
hashedPassword = _a.sent();
return [4 /*yield*/, prisma.user.upsert({
where: { email: 'admin@example.com' },
update: {},
create: {
email: 'admin@example.com',
name: 'Admin User',
password: hashedPassword,
isAdmin: true,
},
})];
case 2:
admin = _a.sent();
console.log({ admin: admin });
return [2 /*return*/];
}
});
});
}
main()
.catch(function (e) {
console.error(e);
process.exit(1);
})
.finally(function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, prisma.$disconnect()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); });
@@ -19,7 +19,7 @@ export class ClientService {
some: {
id: Number(userId),
},
},
},
},
include: {
sharedWith: {
@@ -1,4 +1,13 @@
import { Controller, Get, Param, Req, Res, UseGuards, Logger, Request } from '@nestjs/common';
import {
Controller,
Get,
Param,
Req,
Res,
UseGuards,
Logger,
Request,
} from '@nestjs/common';
import { Response } from 'express';
import { DocumentsService } from './documents.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
@@ -17,7 +26,7 @@ export class DocumentsController {
constructor(
private readonly documentsService: DocumentsService,
private readonly s3Service: S3Service
private readonly s3Service: S3Service,
) {}
@Get('shared/:userId')
@@ -31,17 +40,18 @@ export class DocumentsController {
async downloadDocument(
@Param('key') key: string,
@Request() req,
@Res() res: Response
@Res() res: Response,
) {
try {
this.logger.debug(`Download request for key: ${key}`);
const decodedKey = decodeURIComponent(key);
this.logger.debug(`Decoded key: ${decodedKey}`);
// Get document from database first to verify access
const document = await this.documentsService.findDocumentByS3Key(decodedKey);
const document =
await this.documentsService.findDocumentByS3Key(decodedKey);
if (!document) {
return res.status(404).json({ message: 'Document not found' });
}
@@ -49,7 +59,7 @@ export class DocumentsController {
// Verify user has access to this document
const hasAccess = await this.documentsService.verifyDocumentAccess(
document.id,
req.user.id
req.user.id,
);
if (!hasAccess) {
@@ -58,7 +68,7 @@ export class DocumentsController {
// Get the file from S3
const file = await this.s3Service.getFile(decodedKey);
if (!file || !file.buffer) {
return res.status(404).json({ message: 'File not found in storage' });
}
@@ -72,9 +82,9 @@ export class DocumentsController {
return res.send(file.buffer);
} catch (error) {
this.logger.error('Download error:', error);
return res.status(500).json({
return res.status(500).json({
message: 'Failed to download file',
error: error.message
error: error.message,
});
}
}