Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tusd fix #26

Merged
merged 7 commits into from
Jun 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile.staging
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:18.14.2-alpine
WORKDIR /usr/app
COPY package*.json ./
RUN apk add --no-cache git python3 make g++
RUN apk add --no-cache git python3 make g++ ffmpeg
RUN npm install && npm install typescript -g
COPY . .
RUN tsc
Expand Down
3 changes: 0 additions & 3 deletions caddy/Caddyfile

This file was deleted.

7 changes: 7 additions & 0 deletions caddy/Caddyfile.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
staging.3speak.tv {
handle_path /api/* {
reverse_proxy acela-core:4569
}

reverse_proxy /tusd/* tusd:1080
}
2 changes: 1 addition & 1 deletion docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
- mongo
tusd:
image: tusproject/tusd:v1.9
command: -s3-bucket mybucket -s3-endpoint http://minio:9000 -host=0.0.0.0 -port=1080 -behind-proxy -max-size 5000000000 -hooks-http http://acela-core:4569/api/v1/tus-callback
command: -host=0.0.0.0 -port=1080 -base-path /tusd/files/ -behind-proxy -max-size 5000000000 -hooks-http http://acela-core:4569/v1/upload/tus-callback
volumes:
- ./data/tusd-uploads:/data
networks:
Expand Down
22 changes: 15 additions & 7 deletions docker-compose.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ services:
- "80:80"
- "443:443"
volumes:
- ./caddy/Caddyfile:/etc/caddy/Caddyfile
- ./caddy/Caddyfile.staging:/etc/caddy/Caddyfile
- /data/caddy/data:/data
- /data/caddy/config:/config
networks:
- web
- acela-core
acela-core: # name of the service
environment:
- ACME_AGREE=true
depends_on:
- acela-core
- tusd

acela-core:
build:
context: . # the directory containing Docker context (".", meaning the current directory)
dockerfile: Dockerfile.staging # specify the local Dockerfile
container_name: acela-core # what to label the container for docker ps
restart: always # restart if failed, until we stop it ourselves
context: .
dockerfile: Dockerfile.staging
container_name: acela-core
restart: always
env_file:
- .env.staging
#external_links:
Expand All @@ -32,9 +38,10 @@ services:
UPLOAD_PATH: /acela-uploads
volumes:
- ./data/acela-uploads:/acela-uploads

tusd:
image: tusproject/tusd:v1.9
command: -s3-bucket mybucket -s3-endpoint http://minio:9000 -host=0.0.0.0 -port=1080 -behind-proxy -max-size 5000000000 -hooks-http http://acela-core:4569/api/v1/tus-callback
command: -host=0.0.0.0 -port=1080 -base-path /tusd/files/ -behind-proxy -max-size 5000000000 -hooks-http http://acela-core:4569/v1/upload/tus-callback
volumes:
- ./data/tusd-uploads:/data
networks:
Expand All @@ -45,6 +52,7 @@ services:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
AWS_REGION: eu-west-1

minio:
image: minio/minio:RELEASE.2019-08-14T20-37-41Z
networks:
Expand Down
2 changes: 1 addition & 1 deletion runTusd.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

tusd -upload-dir=./data/ -base-path="/files" -host="127.0.0.1" -port="1080" -behind-proxy --hooks-enabled-events pre-create,post-create,post-finish,post-finish,post-terminate,post-receive -max-size 5000000000 -hooks-http http://localhost:4569/api/v1/upload/tus-callback
tusd -upload-dir=./data/ -base-path="/files" -host="127.0.0.1" -port="1080" -behind-proxy --hooks-enabled-events pre-create,post-create,post-finish,post-finish,post-terminate,post-receive -max-size 5000000000 -hooks-http http://localhost:4569/v1/upload/tus-callback
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function startup(): Promise<void> {
app.useGlobalPipes(new ValidationPipe());
const config = new DocumentBuilder().build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('/api/v1/docs', app, document);
SwaggerModule.setup('/v1/docs', app, document);
await app.listen(4569);
}

Expand Down
16 changes: 8 additions & 8 deletions src/services/api/api.contoller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('ApiController', () => {
await mongod.stop();
});

describe('/POST /api/v1/hive/post_comment', () => {
describe('/POST /v1/hive/post_comment', () => {
it('should post a comment to HIVE blockchain', async () => {
const jwtToken = 'test_jwt_token';
const body = {
Expand All @@ -120,7 +120,7 @@ describe('ApiController', () => {
};

return request(app.getHttpServer())
.post('/api/v1/hive/post_comment')
.post('/v1/hive/post_comment')
.set('Authorization', `Bearer ${jwtToken}`)
.send(body)
.expect(201)
Expand All @@ -135,13 +135,13 @@ describe('ApiController', () => {
});
});

describe('/POST /api/v1/hive/linkaccount', () => {
describe('/POST /v1/hive/linkaccount', () => {
it('should link a Hive account', async () => {
const jwtToken = 'test_jwt_token';
const body = { username: 'test-account' };

return request(app.getHttpServer())
.post('/api/v1/hive/linkaccount')
.post('/v1/hive/linkaccount')
.set('Authorization', `Bearer ${jwtToken}`)
.send(body)
.expect(201)
Expand All @@ -153,12 +153,12 @@ describe('ApiController', () => {
});
});

describe('/GET /api/v1/profile', () => {
describe('/GET /v1/profile', () => {
it('should get the user profile', async () => {
const jwtToken = 'test_jwt_token';

return request(app.getHttpServer())
.get('/api/v1/profile')
.get('/v1/profile')
.set('Authorization', `Bearer ${jwtToken}`)
.expect(200)
.then(response => {
Expand All @@ -172,7 +172,7 @@ describe('ApiController', () => {
});
});

describe('/GET /api/v1/hive/linked-account/list', () => {
describe('/GET /v1/hive/linked-account/list', () => {
it('should list linked accounts', async () => {
const jwtToken = 'test_jwt_token';

Expand All @@ -181,7 +181,7 @@ describe('ApiController', () => {
await linkedAccountsRepository.verify(link._id);

return request(app.getHttpServer())
.get('/api/v1/hive/linked-account/list')
.get('/v1/hive/linked-account/list')
.set('Authorization', `Bearer ${jwtToken}`)
.expect(200)
.then(response => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { LinkedAccountRepository } from '../../repositories/linked-accounts/link
import { EmailService } from '../email/email.service';
import { parseAndValidateRequest } from '../auth/auth.utils';

@Controller('/api/v1')
@Controller('/v1')
export class ApiController {
readonly #logger = new Logger();

Expand Down
16 changes: 8 additions & 8 deletions src/services/auth/auth.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe('AuthController', () => {
const jws = await did.createJWS(payload);

return request(app.getHttpServer())
.post('/api/v1/auth/login/singleton/did')
.post('/v1/auth/login/singleton/did')
.send(jws)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
Expand All @@ -143,7 +143,7 @@ describe('AuthController', () => {

// Make the request to the endpoint
return request(app.getHttpServer())
.post('/api/v1/auth/request_hive_account')
.post('/v1/auth/request_hive_account')
.send({ username: 'test_user_id' })
.set('Authorization', 'Bearer <your_mocked_jwt_token>')
.expect(201)
Expand All @@ -163,7 +163,7 @@ describe('AuthController', () => {

// Make the request to the endpoint
return request(app.getHttpServer())
.post('/api/v1/auth/request_hive_account')
.post('/v1/auth/request_hive_account')
.send({ username: 'yeet' })
.set('Authorization', 'Bearer <your_mocked_jwt_token>')
.expect(400)
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('AuthController', () => {
}

return request(app.getHttpServer())
.post('/api/v1/auth/login/singleton/hive')
.post('/v1/auth/login/singleton/hive')
.send(body)
.expect(201)
.then(response => {
Expand All @@ -214,7 +214,7 @@ describe('AuthController', () => {
}

return request(app.getHttpServer())
.post('/api/v1/auth/login/singleton/hive')
.post('/v1/auth/login/singleton/hive')
.send(body)
.expect(401)
.then(response => {
Expand All @@ -239,7 +239,7 @@ describe('AuthController', () => {
}

return request(app.getHttpServer())
.post('/api/v1/auth/login/singleton/hive')
.post('/v1/auth/login/singleton/hive')
.send(body)
.expect(401)
.then(response => {
Expand All @@ -264,7 +264,7 @@ describe('AuthController', () => {
}

return request(app.getHttpServer())
.post('/api/v1/auth/login/singleton/hive')
.post('/v1/auth/login/singleton/hive')
.send(body)
.expect(401)
.then(response => {
Expand All @@ -287,7 +287,7 @@ describe('AuthController', () => {
}

return request(app.getHttpServer())
.post('/api/v1/auth/login/singleton/hive')
.post('/v1/auth/login/singleton/hive')
.send(body)
.expect(401)
.then(response => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { parseAndValidateRequest } from './auth.utils';
import { RequestHiveAccountDto } from '../api/dto/RequestHiveAccount.dto';
import { HiveService } from '../hive/hive.service';

@Controller('/api/v1/auth')
@Controller('/v1/auth')
export class AuthController {
readonly #logger = new Logger(AuthController.name);

Expand Down
2 changes: 1 addition & 1 deletion src/services/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ import { HiveAccountModule } from '../../repositories/hive-account/hive-account.
})
export class AuthModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer.apply(AuthMiddleware).forRoutes('/api/v1/auth/login_singleton/did');
consumer.apply(AuthMiddleware).forRoutes('/v1/auth/login_singleton/did');
}
}
2 changes: 1 addition & 1 deletion src/services/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class EmailService {
await this.send(
email,
'Complete 3Speak registration',
`test registration. Click <a href="http://${this.configService.get('PUBLIC_CALLBACK_URL') || 'localhost:4569'}/api/v1/auth/verifyemail?code=${email_code}">here</a> to verify email address.`,
`test registration. Click <a href="http://${this.configService.get('PUBLIC_CALLBACK_URL') || 'localhost:4569'}/v1/auth/verifyemail?code=${email_code}">here</a> to verify email address.`,
);
}
}
11 changes: 8 additions & 3 deletions src/services/storage-cluster/allocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@
{
median_size: {
$lt:
(peerInfo.freeSpaceMB! -

Check warning on line 217 in src/services/storage-cluster/allocator.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Forbidden non-null assertion
(peerInfo.totalSpaceMB! * ALLOCATION_DISK_THRESHOLD) / 100) *

Check warning on line 218 in src/services/storage-cluster/allocator.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Forbidden non-null assertion
1048576,
},
},
Expand Down Expand Up @@ -293,6 +293,7 @@
allocations: {
id: peerId,
allocated_at: ts,
reported_size: 0,
},
},
$inc: {
Expand Down Expand Up @@ -410,6 +411,10 @@
const reported_sizes = pinned.allocations
.map((a) => a.reported_size)
.filter((size) => size !== null && typeof size !== 'undefined');
if (!completedPin.size) {
console.error('No size found for pin ' + completedPin.cid);
completedPin.size = 0;
}
reported_sizes.push(completedPin.size);
if (preAllocated === -1) {
await this.pins.updateOne(
Expand All @@ -420,7 +425,7 @@
id: peerId,
allocated_at: msgTs,
pinned_at: msgTs,
reported_size: completedPin.size || 0,
reported_size: completedPin.size,
},
},
$inc: {
Expand Down Expand Up @@ -510,7 +515,7 @@
id: peerId,
allocated_at: msgTs,
pinned_at: msgTs,
reported_size: newPin.size,
reported_size: newPin.size || 0,
};
if (!alreadyExists || alreadyExists.status === 'deleted')
await this.pins.updateOne(
Expand All @@ -524,7 +529,7 @@
last_updated: msgTs,
allocations: [newAlloc],
allocationCount: 1,
median_size: newPin.size || 0, // Ensure median_size is of type number
median_size: newPin.size, // Ensure median_size is of type number
metadata: newPin.metadata || {},
},
},
Expand Down Expand Up @@ -628,7 +633,7 @@
private async handleUnpinRequest(cid: string, msgTs: number) {
try {
await this.ipfs.pin.rm(CID.parse(cid));
} catch {}

Check warning on line 636 in src/services/storage-cluster/allocator.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Empty block statement
await this.removePin(cid, msgTs, true);
}

Expand Down Expand Up @@ -761,7 +766,7 @@

setPeerSynced(peerId: string) {
if (this.hasPeerById(peerId)) {
this.peers[peerId]!.synced = true;

Check warning on line 769 in src/services/storage-cluster/allocator.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Forbidden non-null assertion
}
}

Expand Down Expand Up @@ -797,7 +802,7 @@
this.wss.on('connection', (ws) => {
let authenticated = false;
let peerId: string;
ws.on('message', async (data: Buffer | string) => {

Check warning on line 805 in src/services/storage-cluster/allocator.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Promise returned in function argument where a void return was expected
let message: SocketMsg;
try {
message = JSON.parse(data.toString());
Expand Down
2 changes: 2 additions & 0 deletions src/services/storage-cluster/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
}
const created_at = new Date().getTime();
const info = await this.ipfs.files.stat('/ipfs/' + cid.toString());
this.pins.updateOne(

Check warning on line 105 in src/services/storage-cluster/peer.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
{
_id: cid.toString(),
},
Expand Down Expand Up @@ -208,7 +208,7 @@

private async handlePinAlloc(allocs: SocketMsgPinAlloc, msgTs: number) {
if (allocs.allocations.length === 0) {
setTimeout(() => this.sendPeerInfo(), 30000);

Check warning on line 211 in src/services/storage-cluster/peer.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Promise returned in function argument where a void return was expected
return;
}
Logger.log('Received ' + allocs.allocations.length + ' pin allocations', 'storage-peer');
Expand All @@ -232,6 +232,7 @@
allocations: {
id: this.getPeerId(),
allocated_at: msgTs,
reported_size: 0,
},
},
$inc: {
Expand Down Expand Up @@ -348,6 +349,7 @@
type: SocketMsgTypes.PIN_FAILED,
data: {
cid: cid,
size: 0,
},
ts: failedTs,
});
Expand Down
2 changes: 1 addition & 1 deletion src/services/storage-cluster/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export interface PinAllocate {
id: string;
allocated_at: number;
pinned_at?: number | undefined;
reported_size?: number | undefined;
reported_size: number;
}

export interface Pin {
Expand Down
2 changes: 1 addition & 1 deletion src/services/uploader/uploading.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('UploadingController', () => {
.toBuffer();

return request(app.getHttpServer())
.post('/api/v1/upload/thumbnail')
.post('/v1/upload/thumbnail')
.set('Authorization', `Bearer ${jwtToken}`)
.attach('file', semiTransparentRedPng, 'test-image.png')
.field('video_id', 'test_video_id')
Expand Down
2 changes: 1 addition & 1 deletion src/services/uploader/uploading.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ MulterModule.registerAsync({
}),
});

@Controller('/api/v1/upload')
@Controller('/v1/upload')
export class UploadingController {
readonly #logger = new Logger(UploadingController.name);

Expand Down
Loading