Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ build_frontend:

docker push "$CI_APPLICATION_REPOSITORY/1694.io-frontend:$CI_APPLICATION_TAG"
docker push "$CI_APPLICATION_REPOSITORY/1694.io-frontend:latest"
only:
- branches
rules:
- if: '$DEPLOY_WEBSITE == "true"'

build_backend:
stage: build
Expand All @@ -160,8 +160,8 @@ build_backend:
-t "$CI_APPLICATION_REPOSITORY/1694.io-backend:latest" .
docker push "$CI_APPLICATION_REPOSITORY/1694.io-backend:$CI_APPLICATION_TAG"
docker push "$CI_APPLICATION_REPOSITORY/1694.io-backend:latest"
only:
- branches
rules:
- if: '$DEPLOY_WEBSITE == "true"'

.deploy_postgres_web: &deploy_postgres_web
<<: *deploy_template
Expand Down Expand Up @@ -252,8 +252,8 @@ app-sancho:
- job: build_backend
environment:
name: sancho
only:
- branches
rules:
- if: '$DEPLOY_WEBSITE == "true"'

postgres-app-preview:
<<: *deploy_postgres_web
Expand Down Expand Up @@ -388,7 +388,7 @@ production:
needs:
- job: app-preview
rules:
- if: $CI_COMMIT_BRANCH == 'main'
- if: '$CI_COMMIT_BRANCH == "main" && ($DEPLOY_WEBSITE == "true")'
when: manual

ui-chrome-tests:
Expand Down
10 changes: 10 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
BLOCKFROST_NETWORK_PROJECT_ID=
BLOCKFROST_NETWORK_URL=
BLOCKFROST_IPFS_URL=
BLOCKFROST_IPFS_PROJECT_ID=
BLOCKFROST_NETWORK_PROJECT_ID_FALLBACK=
BLOCKFROST_NETWORK_URL_FALLBACK=
BLOCKFROST_IPFS_URL_FALLBACK=
BLOCKFROST_IPFS_PROJECT_ID_FALLBACK=
DATABASE_HOST=
DATABASE_PORT=
DATABASE_USERNAME=
DATABASE_PASSWORD=
DATABASE_NAME=
IPFS_GATEWAY=
8 changes: 7 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
"migration:make": "yarn run typeorm migration:create -d src/typeorm.config.ts -n",
"migration:generate": "yarn run typeorm migration:generate -d src/typeorm.config.ts",
"migration:show": "yarn run typeorm migration:show -d src/typeorm.config.ts",
"migrate:up": "yarn run typeorm migration:run -d src/typeorm.config.ts",
"migrate:down": "yarn run typeorm migration:revert -d src/typeorm.config.ts"
},
"dependencies": {
"@nestjs/axios": "^3.0.2",
Expand Down
4 changes: 3 additions & 1 deletion backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { AuthService } from './auth/auth.service';
import { ProposalsModule } from './proposals/proposals.module';
import { MiscellaneousModule } from './miscellaneous/miscellaneous.module';
import {NotificationsModule} from "./notifications/notifications.module";
import { BlockfrostModule } from './blockfrost/blockfrost.module';

@Module({
imports: [
Expand All @@ -31,7 +32,8 @@ import {NotificationsModule} from "./notifications/notifications.module";
ReactionsModule,
ProposalsModule,
MiscellaneousModule,
NotificationsModule
NotificationsModule,
BlockfrostModule
],
controllers: [],
providers: [AuthService],
Expand Down
3 changes: 2 additions & 1 deletion backend/src/attachment/attachment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Attachment } from 'src/entities/attachment.entity';
import { AttachmentController } from './attachment.controller';
import { HttpModule } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { BlockfrostService } from 'src/blockfrost/blockfrost.service';

@Module({
imports: [
Expand All @@ -15,6 +16,6 @@ import { ConfigService } from '@nestjs/config';
}),
],
controllers: [AttachmentController],
providers: [AttachmentService, ConfigService],
providers: [AttachmentService, BlockfrostService]
})
export class AttachmentModule {}
42 changes: 17 additions & 25 deletions backend/src/attachment/attachment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import {
IPFSResponse,
} from 'src/common/types';
import { HttpService } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { Response } from 'express';
import { BlockfrostService } from 'src/blockfrost/blockfrost.service';

@Injectable()
export class AttachmentService {
constructor(
@InjectDataSource('default')
private voltaireService: DataSource,
private httpService: HttpService,
private configService: ConfigService,
private blockfrostService: BlockfrostService,
) {}
async parseMimeType(mimeType: string) {
switch (mimeType) {
Expand Down Expand Up @@ -200,24 +200,24 @@ export class AttachmentService {
try {
const res = await lastValueFrom(
this.httpService.post(
'https://ipfs.blockfrost.io/api/v0/ipfs/add',
`${this.blockfrostService.blockfrostIPFSURL}/api/v0/ipfs/add`,
attachment,
{
headers: {
project_id: this.configService.get<string>(
'BLOCKFROST_IPFS_PROJECT_ID',
),
project_id: this.blockfrostService.blockfrostIPFSProjectID,
},
},
),
);
const ipfsRes = res.data as IPFSResponse;
//then auto-pin the attachment
const ipfsPinStatus =await this.pinAttachmentToIPFS(ipfsRes.ipfs_hash) as IPFSPinResponse;
const ipfsPinStatus = (await this.pinAttachmentToIPFS(
ipfsRes.ipfs_hash,
)) as IPFSPinResponse;
return {
...ipfsRes,
state: ipfsPinStatus.state
}
state: ipfsPinStatus.state,
};
} catch (error) {
console.error(error.response.data || error.response || error);
throw new HttpException(error.response.data, error.response.status);
Expand All @@ -227,13 +227,11 @@ export class AttachmentService {
try {
const res = await lastValueFrom(
this.httpService.post(
`https://ipfs.blockfrost.io/api/v0/ipfs/pin/add/${hash}`,
`${this.blockfrostService.blockfrostIPFSURL}/api/v0/ipfs/pin/add/${hash}`,
{},
{
headers: {
project_id: this.configService.get<string>(
'BLOCKFROST_IPFS_PROJECT_ID',
),
project_id: this.blockfrostService.blockfrostIPFSProjectID,
},
},
),
Expand All @@ -248,12 +246,10 @@ export class AttachmentService {
try {
const res = await lastValueFrom(
this.httpService.get(
`https://ipfs.blockfrost.io/api/v0/ipfs/pin/list/${hash}`,
`${this.blockfrostService.blockfrostIPFSURL}/api/v0/ipfs/pin/list/${hash}`,
{
headers: {
project_id: this.configService.get<string>(
'BLOCKFROST_IPFS_PROJECT_ID',
),
project_id: this.blockfrostService.blockfrostIPFSProjectID,
},
},
),
Expand All @@ -268,13 +264,11 @@ export class AttachmentService {
try {
const res = await lastValueFrom(
this.httpService.post(
`https://ipfs.blockfrost.io/api/v0/ipfs/pin/remove/${hash}`,
`${this.blockfrostService.blockfrostIPFSURL}/api/v0/ipfs/pin/remove/${hash}`,
{},
{
headers: {
project_id: this.configService.get<string>(
'BLOCKFROST_IPFS_PROJECT_ID',
),
project_id: this.blockfrostService.blockfrostIPFSProjectID,
},
},
),
Expand All @@ -289,12 +283,10 @@ export class AttachmentService {
try {
const response = await lastValueFrom(
this.httpService.get(
`https://ipfs.blockfrost.io/api/v0/ipfs/gateway/${hash}`,
`${this.blockfrostService.blockfrostIPFSURL}/api/v0/ipfs/gateway/${hash}`,
{
headers: {
project_id: this.configService.get<string>(
'BLOCKFROST_IPFS_PROJECT_ID',
),
project_id: this.blockfrostService.blockfrostIPFSProjectID,
},
responseType: 'stream', // Used stream to handle large files or non-JSON data
},
Expand Down
46 changes: 41 additions & 5 deletions backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { Global, Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import jwtConstants from './jwtConstants';
import { InjectDataSource } from '@nestjs/typeorm';
import { DataSource } from 'typeorm';
type Payload = {
drepId?: string;
voterId?: string;
stakeKey: string;
signature: string;
key: string;
};
@Injectable()
export class AuthService {
constructor(private jwtService: JwtService) {}
async signJWT(payload: any, tte: number | string) {
constructor(
private jwtService: JwtService,
@InjectDataSource('default')
private voltaireService: DataSource,
) {}
async signJWT(payload: Payload, tte: number | string) {
const accessSecret = jwtConstants.secret;
return this.jwtService.signAsync(payload, {
secret: accessSecret,
Expand All @@ -17,11 +30,34 @@ export class AuthService {
secret: accessSecret,
});
}
//the payload could consist of the
async login(payload: any, tte: number | string) {
//the payload could consist of the
async login(payload: Payload, tte: number | string) {
//basically should check if the user signature is valid in the case of a drep or just provide a token for a normal user.
const token = await this.signJWT(payload, tte);
return { token };
const signatureDto = {
drep: payload.drepId,
voterId: payload.voterId,
stakeKey: payload.stakeKey,
signatureKey: payload.key,
signature: payload.signature,
};
//check for existing signature
const existingSig = await this.voltaireService
.getRepository('Signature')
.findOne({
where: { signature: payload.signature, signatureKey:payload.key, stakeKey: payload.stakeKey, },
});
if (existingSig) {
//update the signature
const updatedSig=await this.voltaireService
.getRepository('Signature')
.update(existingSig.id, signatureDto)
return { token, updatedSig };
}
const insertedSig = await this.voltaireService
.getRepository('Signature')
.insert(signatureDto);
return { token, insertedSig };
}
async verifyLogin(token: string) {
// should check if there is an existing drep signature in the db. Well this is for dreps who have a profile.
Expand Down
13 changes: 13 additions & 0 deletions backend/src/blockfrost/blockfrost.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { BlockfrostService } from './blockfrost.service';
import { HttpModule } from '@nestjs/axios';

@Module({
imports: [
HttpModule.register({
maxRedirects: 5,
}),
],
providers: [BlockfrostService],
})
export class BlockfrostModule {}
Loading