Zip handout files by default, add zip option to challenge schema to disable. Respect handout_dir - #16
Conversation
… disable. Respect handout_dir
|
All Contributors have signed the CLA. Thank you for your cooperation! |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Pull request overview
This PR changes how challenge handout files are collected and uploaded to CTFd: it now walks the handout directory recursively and (by default) uploads a single zip archive, with a new per-challenge schema option to disable zipping and a handout_dir override.
Changes:
- Add recursive GitHub directory walking to include nested handout subdirectories.
- Zip handout files by default before uploading to CTFd; add
zipschema option to opt out. - Respect a configurable
handout_dirin the challenge schema (defaulting tohandout).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/github.go | Adds recursive directory traversal helper to enumerate files under a handout directory. |
| src/ctfd-challenges.go | Switches to recursive file collection and optionally zips handouts before uploading to CTFd. |
| src/challenge.go | Extends challenge schema with handout_dir and zip, and updates handout directory resolution helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| nested, err := getGithubDirContentsRecursive(repo, branch, entryPath) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| files = append(files, nested...) | ||
| continue | ||
| } | ||
|
|
||
| files = append(files, RemoteFile{ | ||
| Path: entryPath, | ||
| RelPath: strings.TrimPrefix(entryPath, path+"/"), | ||
| }) |
| if challengeConfig.Challenge.HandoutDir != "" { | ||
| return challengeConfig.Challenge.HandoutDir | ||
| } | ||
| return "handout" | ||
| } |
The0mikkel
left a comment
There was a problem hiding this comment.
Overall I like the approach, however there are some elements I would have liked to be changed, before diving deeper into the code.
First, as ctfpilot/challenge-schema#17 is not being implemented, the zipping functionality should be ctfd-manager wide. This should make the ctfd-manager follow the handout_dir in the challenge config, and zip those files into a single zip that can be uploaded.
The part of the code, handling zipping, I would like to have in a seperate file, such that it may be reused across code if needed, and generalle abstract the zipping process out of this part of the code.
With this, the ctfd-manager will not zip on challenge specific, but will be application wide.
As a note on the zipping process, it should put the files in the following format: <category>_<slug>
Such that when the zip is extracted, a folder named <category>_<slug> is presented.
The zip file should be named in the same way.
|
Updated the PR to always zip for multiple files and have the correct file name @The0mikkel |
No description provided.