Repository navigation
feat(custom-client): replace Nexus with GitHub Actions-based custom client builder #473
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
Open
hashbk
wants to merge
7
commits into
databk:main
Choose a base branch
from
hashbk:feat/custom-client-builder
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
106c2c1
feat(custom-client): replace Nexus with GitHub Actions-based custom c…
hashbk 14332af
feat(custom-client): dispatch per-platform workflows instead of custo…
hashbk ce68db7
feat(custom-client): support all-platform builds via flutter-build wo…
hashbk 434ba71
fix(custom-client): register migration in mysql integration spec
hashbk 5efa882
feat(custom-client): expose build progress via GitHub runs API
hashbk f6916c6
fix(custom-client): address CodeRabbit review comments
hashbk 2546cc8
fix(migration): change MySQL message column from varchar(255) to text
hashbk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/migrations/1791212800000-ReplaceNexusWithCustomClientBuilds.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class ReplaceNexusWithCustomClientBuilds1791212800000 implements MigrationInterface { | ||
| name = 'ReplaceNexusWithCustomClientBuilds1791212800000'; | ||
|
|
||
| async up(queryRunner: QueryRunner): Promise<void> { | ||
| const type = queryRunner.connection.options.type; | ||
|
|
||
| // Drop legacy Nexus tables (replaced by the custom-client module). | ||
| if (await queryRunner.hasTable('nexus_tokens')) { | ||
| await queryRunner.dropTable('nexus_tokens'); | ||
| } | ||
| if (await queryRunner.hasTable('nexus_builds')) { | ||
| await queryRunner.dropTable('nexus_builds'); | ||
| } | ||
|
|
||
| if (await queryRunner.hasTable('custom_client_builds')) { | ||
| return; | ||
| } | ||
|
|
||
| if (type === 'sqlite') { | ||
| await queryRunner.query( | ||
| `CREATE TABLE "custom_client_builds" ("uuid" varchar PRIMARY KEY NOT NULL, "userGuid" varchar NOT NULL, "os" varchar NOT NULL, "arch" varchar NOT NULL, "custom" text, "status" varchar NOT NULL DEFAULT ('pending'), "message" text, "files" text, "callbackToken" varchar NOT NULL, "githubRunId" varchar, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')))`, | ||
| ); | ||
| await queryRunner.query( | ||
| `CREATE INDEX "IDX_custom_client_builds_userGuid" ON "custom_client_builds" ("userGuid") `, | ||
| ); | ||
| await queryRunner.query( | ||
| `CREATE INDEX "IDX_custom_client_builds_status" ON "custom_client_builds" ("status") `, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| if (type === 'mysql') { | ||
| await queryRunner.query( | ||
| `CREATE TABLE \`custom_client_builds\` (\`uuid\` varchar(255) NOT NULL, \`userGuid\` varchar(255) NOT NULL, \`os\` varchar(255) NOT NULL, \`arch\` varchar(255) NOT NULL, \`custom\` text NULL, \`status\` varchar(255) NOT NULL DEFAULT 'pending', \`message\` text NULL, \`files\` text NULL, \`callbackToken\` varchar(255) NOT NULL, \`githubRunId\` varchar(255) NULL, \`createdAt\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updatedAt\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), INDEX \`IDX_custom_client_builds_userGuid\` (\`userGuid\`), INDEX \`IDX_custom_client_builds_status\` (\`status\`), PRIMARY KEY (\`uuid\`)) ENGINE=InnoDB`, | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| throw new Error(`Unsupported database type: ${type}`); | ||
| } | ||
|
|
||
| async down(queryRunner: QueryRunner): Promise<void> { | ||
| if (await queryRunner.hasTable('custom_client_builds')) { | ||
| await queryRunner.dropTable('custom_client_builds'); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import { | ||
| Controller, | ||
| Get, | ||
| Post, | ||
| Put, | ||
| Delete, | ||
| Body, | ||
| Param, | ||
| Res, | ||
| Req, | ||
| HttpCode, | ||
| HttpStatus, | ||
| NotFoundException, | ||
| UseGuards, | ||
| UseInterceptors, | ||
| UploadedFiles, | ||
| } from '@nestjs/common'; | ||
| import { FilesInterceptor } from '@nestjs/platform-express'; | ||
| import type { Request, Response } from 'express'; | ||
| import { createReadStream, existsSync, statSync } from 'fs'; | ||
| import { basename } from 'path'; | ||
| import { CustomClientService } from './custom-client.service'; | ||
| import { CustomClientSettingsService } from './services/custom-client-settings.service'; | ||
| import { SubmitBuildDto } from './dto/custom-client-build.dto'; | ||
| import { UpdateCustomClientSettingsDto } from './dto/custom-client-settings.dto'; | ||
| import { CurrentUser } from '../auth/decorators/current-user.decorator'; | ||
| import { Public } from '../auth/decorators/public.decorator'; | ||
| import { AdminGuard } from '../../common/guards/admin.guard'; | ||
|
|
||
| @Controller('custom-client') | ||
| export class CustomClientController { | ||
| constructor( | ||
| private readonly customClientService: CustomClientService, | ||
| private readonly settingsService: CustomClientSettingsService, | ||
| ) {} | ||
|
|
||
| @Post('builds') | ||
| @HttpCode(HttpStatus.CREATED) | ||
| async createBuild( | ||
| @CurrentUser('id') userGuid: string, | ||
| @Body() dto: SubmitBuildDto, | ||
| ) { | ||
| return this.customClientService.submitBuild(userGuid, dto); | ||
| } | ||
|
|
||
| @Get('builds') | ||
| async listBuilds(@CurrentUser('id') userGuid: string) { | ||
| return this.customClientService.listBuilds(userGuid); | ||
| } | ||
|
|
||
| @Delete('builds/:uuid') | ||
| @HttpCode(HttpStatus.NO_CONTENT) | ||
| async deleteBuild( | ||
| @CurrentUser('id') userGuid: string, | ||
| @Param('uuid') uuid: string, | ||
| ) { | ||
| await this.customClientService.deleteBuild(userGuid, uuid); | ||
| } | ||
|
|
||
| @Get('builds/:uuid/files') | ||
| async listBuildFiles( | ||
| @CurrentUser('id') userGuid: string, | ||
| @Param('uuid') uuid: string, | ||
| ) { | ||
| return this.customClientService.listBuildFiles(uuid, userGuid); | ||
| } | ||
|
|
||
| @Get('builds/:uuid/files/:filename') | ||
| async downloadBuildFile( | ||
| @CurrentUser('id') userGuid: string, | ||
| @Param('uuid') uuid: string, | ||
| @Param('filename') filename: string, | ||
| @Res() res: Response, | ||
| ) { | ||
| const filePath = await this.customClientService.getLocalFilePath( | ||
| uuid, | ||
| filename, | ||
| userGuid, | ||
| ); | ||
| if (!existsSync(filePath)) { | ||
| throw new NotFoundException('File not found'); | ||
| } | ||
| const stat = statSync(filePath); | ||
| res.setHeader('Content-Type', 'application/octet-stream'); | ||
| res.setHeader( | ||
| 'Content-Disposition', | ||
| `attachment; filename="${basename(filePath)}"`, | ||
| ); | ||
| res.setHeader('Content-Length', stat.size); | ||
| const stream = createReadStream(filePath); | ||
| stream.pipe(res); | ||
| } | ||
|
|
||
| @Get('builds/:uuid/progress') | ||
| async getBuildProgress( | ||
| @CurrentUser('id') userGuid: string, | ||
| @Param('uuid') uuid: string, | ||
| ) { | ||
| return this.customClientService.getBuildProgress(uuid, userGuid); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| @Post('builds/:uuid/callback') | ||
| @Public() | ||
| @UseInterceptors( | ||
| FilesInterceptor('files', 10, { | ||
| limits: { fileSize: 200 * 1024 * 1024, files: 10 }, | ||
| }), | ||
| ) | ||
| @HttpCode(HttpStatus.OK) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| async handleCallback( | ||
| @Param('uuid') uuid: string, | ||
| @Req() req: Request, | ||
| @Body() body: { status?: string; message?: string }, | ||
| @UploadedFiles() files: Express.Multer.File[], | ||
| ) { | ||
| const callbackToken = String(req.headers['x-callback-token'] ?? ''); | ||
| await this.customClientService.handleCallback( | ||
| uuid, | ||
| callbackToken, | ||
| body?.status ?? 'completed', | ||
| body?.message, | ||
| files ?? [], | ||
| ); | ||
| return { message: 'Callback processed' }; | ||
| } | ||
|
|
||
| @Get('settings') | ||
| @UseGuards(AdminGuard) | ||
| async getSettings() { | ||
| return this.settingsService.getSettings(); | ||
| } | ||
|
|
||
| @Put('settings') | ||
| @UseGuards(AdminGuard) | ||
| @HttpCode(HttpStatus.OK) | ||
| async updateSettings(@Body() dto: UpdateCustomClientSettingsDto) { | ||
| return this.settingsService.updateSettings(dto); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { Module } from '@nestjs/common'; | ||
| import { TypeOrmModule } from '@nestjs/typeorm'; | ||
| import { CustomClientController } from './custom-client.controller'; | ||
| import { CustomClientService } from './custom-client.service'; | ||
| import { CustomClientBuild } from './entities/custom-client-build.entity'; | ||
| import { CustomClientSettingsService } from './services/custom-client-settings.service'; | ||
| import { SystemSetting } from '../settings/entities/system-setting.entity'; | ||
| import { SettingsModule } from '../settings/settings.module'; | ||
|
|
||
| @Module({ | ||
| imports: [ | ||
| TypeOrmModule.forFeature([CustomClientBuild, SystemSetting]), | ||
| SettingsModule, | ||
| ], | ||
| controllers: [CustomClientController], | ||
| providers: [CustomClientService, CustomClientSettingsService], | ||
| exports: [CustomClientService, CustomClientSettingsService], | ||
| }) | ||
| export class CustomClientModule {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: databk/rustdesk-console
Length of output: 20548
Script executed:
Repository: databk/rustdesk-console
Length of output: 39861
Web query:
Express 5 req.params decodeURIComponent route parameter encoded dot %2e Node fs createReadStream directory error pipe error handlerResult:
Script executed:
Repository: databk/rustdesk-console
Length of output: 3668
Web query:
site:nodejs.org/docs/latest-v24.x/api stream pipe readable error destination not closed unhandled error event process exitsResult:
Reject directories and handle download stream errors.
For an owned build with a directory, a request with
%2eas the filename can reachcreateReadStreamwith that directory. On Linux, the read fails asynchronously and can terminate the server process.Suggested fix