### Install Hydro Components and Start Service Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/riscv.en.mdx Installs essential command-line tools and Hydro components using Nix and Yarn, then starts the Hydro service with PM2. ```bash nix profile add nixpkgs#bashInteractive nixpkgs#nodejs nixpkgs#yarn nixpkgs#pm2 nixpkgs#gawk \ nixpkgs#go-judge nixpkgs#gcc # and other compilers... yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge hydrooj addon add @hydrooj/ui-default hydrooj addon add @hydrooj/hydrojudge pm2 start hydrooj ``` -------------------------------- ### Install Nix Environment Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/upgrade.md If you don't have nix installed, use this command to set it up. ```bash . <(curl https://hydro.ac/nix.sh) ``` -------------------------------- ### Install Hydro Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/index.en.mdx Run this command to start the Hydro installation. Ensure you have root privileges. ```sh LANG=en . <(curl https://hydro.ac/setup.sh) ``` -------------------------------- ### Install Hydro with No Caddy Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/index.en.mdx Example of using an advanced flag to skip reverse proxy setup during installation. The service will listen only on 127.0.0.1:8888. ```sh . <(curl https://hydro.ac/setup.sh) --no-caddy ``` -------------------------------- ### Install Nix and Core Components Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/upgrade.en.md Ensure Nix is installed by sourcing the provided script, then use Nix to install Node.js, Yarn, and PM2. This is a prerequisite for managing Node.js environments with Nix. ```bash . <(curl https://hydro.ac/nix.sh) ``` ```bash nix-env -iA nixpkgs.nodejs nixpkgs.yarn nixpkgs.pm2 ``` -------------------------------- ### Install HydroJudge as Add-on Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/hydrojudge.en.mdx Run these commands to install HydroJudge as an add-on on the same server as Hydro. Requires restarting Hydro. ```sh yarn global add @hydrooj/hydrojudge hydrooj addon add @hydrooj/hydrojudge ``` -------------------------------- ### Initialize Nix Environment Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/riscv.en.mdx Fetches and executes the Nix installation script. Configure additional binary caches for faster builds. ```bash curl -sSL https://hydro.ac/nix.sh | bash ``` -------------------------------- ### Install sonic-server using Nix Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/sonic.md Installs the sonic-server package using the Nix package manager. Requires root privileges. ```bash nix-env -iA nixpkgs.sonic-server ``` -------------------------------- ### Install Nix Packages Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/compiler.en.mdx Use this command to install new compilers or packages via nix. Remember to restart the sandbox for changes to take effect. ```sh nix-env -iA nixpkgs.coreutils nixpkgs.bash nixpkgs.gawk nixpkgs.unzip # Base components, pre-installed, do not remove nix-env -iA nixpkgs.gcc nixpkgs.fpc # C/C++ and Pascal, pre-installed, do not remove nix-env -iA nixpkgs.ghc # Haskell nix-env -iA nixpkgs.rustc # Rust nix-env -iA nixpkgs.python3Minimal nix-env -iA nixpkgs.python3Packages.numpy nix-env -iA nixpkgs.pypy3 nix-env -iA nixpkgs.php nix-env -iA nixpkgs.go # Golang nix-env -iA nixpkgs.nodejs nix-env -iA nixpkgs.openjdk_headless # Java nix-env -iA nixpkgs.ruby nix-env -iA nixpkgs.mono # C# nix-env -iA nixpkgs.julia_17-bin # Julia nix-env -iA nixpkgs.iverilog # Verilog ``` -------------------------------- ### Install Sonic HydroOJ Addon Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/sonic.md Installs the @hydrooj/sonic addon globally using yarn and then adds it to HydroOJ. Requires root privileges. ```bash yarn global add @hydrooj/sonic hydrooj addon add @hydrooj/sonic ``` -------------------------------- ### Sonic Configuration Example Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/sonic.en.md A TOML configuration file for the Sonic search backend. This example covers server, channel, search, and store settings. Ensure 'auth_password' is set securely. ```toml # Sonic # Fast, lightweight and schema-less search backend # Configuration file # Example: https://github.com/valeriansaliou/sonic/blob/master/config.cfg [server] log_level = "error" [channel] inet = "127.0.0.1:1491" # listens on localhost by default tcp_timeout = 300 auth_password = "SecretPassword" [channel.search] query_limit_default = 10 query_limit_maximum = 100 query_alternates_try = 4 suggest_limit_default = 5 suggest_limit_maximum = 20 [store] [store.kv] path = "/data/sonic/store/kv/" retain_word_objects = 1000 [store.kv.pool] inactive_after = 1800 [store.kv.database] flush_after = 900 compress = true parallelism = 2 max_files = 10 max_compactions = 1 max_flushes = 1 write_buffer = 16384 write_ahead_log = true [store.fst] path = "/data/sonic/store/fst/" [store.fst.pool] inactive_after = 300 [store.fst.graph] consolidate_after = 180 max_size = 2048 max_words = 250000 ``` -------------------------------- ### Install Node.js, Yarn, and PM2 with Nix Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/upgrade.md Reinstall Node.js, Yarn, and PM2 using nix-env after setting up the nix environment. ```bash nix-env -iA nixpkgs.nodejs nixpkgs.yarn nixpkgs.pm2 ``` -------------------------------- ### Start Sonic Server with PM2 Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/sonic.md Starts the Sonic server using PM2 process manager, specifying the configuration file. Saves the current PM2 process list. ```bash pm2 start sonic -- -c /root/.sonic/config.cfg pm2 save ``` -------------------------------- ### Create a Local Addon Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/system/frontend-modify.en.mdx Run this command to create a local addon if you have not done so before. This is necessary for modifying files in a deployed installation. ```bash hydrooj addon create ``` -------------------------------- ### Install Plugin with Yarn Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/index.en.mdx Install a plugin globally using yarn and then add it to Hydro. Ensure the plugin is installed globally before adding it to Hydro. ```sh yarn global add @hydrooj/geoip hydrooj addon add @hydrooj/geoip ``` -------------------------------- ### Install Python Libraries and Restart Sandbox Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/index.en.mdx If you installed Python before August 12, 2022, use this command to install numpy and other libraries, then restart the Hydro sandbox. For newer installations, refer to the Compiler section. ```bash pip3 install numpy && pm2 restart hydro-sandbox ``` -------------------------------- ### Install Only Judge Component Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/index.en.mdx Example of using an advanced flag to install only the standalone judge component. ```sh . <(curl https://hydro.ac/setup.sh) --judge ``` -------------------------------- ### Run Development Server with Debugging and Watch Mode Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/index.en.mdx Start the backend development server with a specified port, verbose debug logging, and backend hot-reloading enabled. ```bash yarn debug --port=8888 --watch ``` -------------------------------- ### Full config.yaml Example for Problem Settings Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/user/testdata.en.mdx Demonstrates the comprehensive configuration options available in config.yaml, covering problem type, global and per-testcase limits, custom checkers, interactors, extra files, subtasks, and language settings. ```yaml # Problem type: default (standard comparison), objective, or interactive. type: default # Global limits (overridden by per-testcase limits). time: 1s memory: 128m # Input/Output Filename (e.g., foo.in / foo.out). # Remove this for Standard I/O (stdin/stdout). filename: foo # Options for type: default # Checker type: default (ignores trailing whitespace/newlines), # testlib (common), hustoj, lemon, etc. checker_type: default # Path to the custom checker (if not default). # Language is identified by extension (.cc for C++). checker: chk.cc # Path to the interactor (required for interactive problems). interactor: interactor.cc # Extra files to be copied into the judge working directory. user_extra_files: - helper_input.txt judge_extra_files: - secret_data.txt # Test Case Configuration # If CASES and SUBTASKS are missing, the system defaults to automatic recognition. subtasks: - score: 30 type: min # min/max/sum: score for the subtask based on cases within it. time: 1s memory: 64m cases: - time: 0.5s memory: 32m input: a.in output: a.out - input: b.in output: b.out - score: 70 time: 0.5s memory: 32m if: [0] # Dependent on passing subtask 0. cases: - input: c.in output: c.out - input: d.in output: d.out # Permitted Languages (Must match judge machine lang.yaml IDs). langs: - c - cc - cc.cc11o2 - pas # Per-language Time/Memory multipliers. time_limit_rate: py.py3: 2 memory_limit_rate: java: 1.5 ``` -------------------------------- ### Stop and Delete All Processes Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/debug.en.md If processes are missing or failing, stop and delete all existing processes before rerunning the installation script. ```bash pm2 stop all && pm2 del all ``` -------------------------------- ### Start Standalone HydroJudge Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/hydrojudge.en.mdx Run this command to start the standalone HydroJudge process. It can be managed with pm2 for background execution. ```sh hydrojudge ``` -------------------------------- ### Install Dependencies and Update Lockfile Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/index.en.mdx Run this command in the HydroOJ directory to resolve outdated lockfile issues and ensure all dependencies are correctly installed. ```bash cd `yarn global dir` && rm -rf node_modules yarn.lock && yarn install ``` -------------------------------- ### Sonic Server Configuration Example Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/sonic.md A TOML configuration file for the Sonic search backend. Customize paths, ports, and authentication as needed. Ensure the 'auth_password' matches the HydroOJ configuration. ```toml # Sonic # Fast, lightweight and schema-less search backend # Configuration file # Example: https://github.com/valeriansaliou/sonic/blob/master/config.cfg [server] log_level = "error" [channel] inet = "127.0.0.1:1491" # 默认监听本机 tcp_timeout = 300 auth_password = "SecretPassword" [channel.search] query_limit_default = 10 query_limit_maximum = 100 query_alternates_try = 4 suggest_limit_default = 5 suggest_limit_maximum = 20 [store] [store.kv] path = "/data/sonic/store/kv/" retain_word_objects = 1000 [store.kv.pool] inactive_after = 1800 [store.kv.database] flush_after = 900 compress = true parallelism = 2 max_files = 100 max_compactions = 1 max_flushes = 1 write_buffer = 16384 write_ahead_log = true [store.fst] path = "/data/sonic/store/fst/" [store.fst.pool] inactive_after = 300 [store.fst.graph] consolidate_after = 180 max_size = 2048 max_words = 250000 ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/index.en.mdx Clone the Hydro repository and install necessary dependencies using Yarn. Ensure submodules are included during cloning. ```bash git clone https://github.com/hydro-dev/Hydro.git --recursive cd Hydro yarn ``` -------------------------------- ### User Import Data Examples Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/system/import-user.en.mdx Examples of user data formats for import. Supports CSV (comma-separated) and TAB-separated formats. Ensure UTF-8 encoding for proper character display. The user profile column is unavailable in CSV format. ```text foo@undefined.moe user1 password1 bar@undefined.moe user2 password2 temp test@undefined.moe user3 password3 test {"group":"class1","studentId":"123","school":"Hydro School"} ``` -------------------------------- ### Compile Java Code Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/compiler.en.mdx Example command for compiling Java code and creating a JAR file. This can be used to test compilation performance. ```sh javac -d /w -encoding utf8 ./Main.java && jar cvf Main.jar *.class ``` -------------------------------- ### Verify Hydro Service Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/upgrade.en.md Check the logs for the Hydro service to confirm a successful startup. Look for the 'Server started' message within the last 100 lines. ```bash pm2 logs hydrooj --lines 100 ``` -------------------------------- ### Run Frontend Watcher Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/index.en.mdx Start the frontend watcher to transpile UI changes in real-time during development. This should be run in a separate terminal from the backend server. ```bash yarn build:ui:dev ``` -------------------------------- ### Example Directory Structure for Automatic Recognition Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/user/testdata.en.mdx Illustrates the required file naming convention for automatic test data recognition, using numeric suffixes for .in and .out files. ```bash # Example Directory Structure: . ├── a1.in ├── a1.out ├── a2.in ├── a2.out ├── a3.in └── a3.out ``` -------------------------------- ### Build Custom Nix Environment Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/compiler.en.mdx Define a custom Nix environment by specifying required packages and build scripts. This is useful for complex compilation setups. ```nix { system ? builtins.currentSystem, pkgs ? import { system = system; } }: pkgs.buildEnv { name = "hydrojudge-rootfs"; paths = with pkgs; [ coreutils bash nix zip unzip gcc gawk # The packages above are required for judging, do not remove them. # List the packages you need below, search method is the same as above: fpc python3 rustc ]; ignoreCollisions = true; pathsToLink = [ "/" ]; # Export some basic info and /etc/passwd required by some compilers postBuild = '' mkdir $out/buildInfo echo 'root:x:0:0:root:/root:/bin/bash' >$out/etc/passwd date >$out/buildInfo/timestamp ''; } ``` -------------------------------- ### Example Training Plan Structure Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/user/domain.mdx This JSON structure defines a training plan with multiple chapters. Each chapter has an ID, title, required preceding chapters, and a list of associated problem IDs. Use this format when creating new training plans. ```json [ { "_id": 1, "title": "入门", "requireNids": [], "pids": [1] }, { "_id": 2, "title": "精通", "requireNids": [], "pids": [2] }, { "_id": 3, "title": "大师", "requireNids": [1,2], "pids": [3] } ] ``` -------------------------------- ### Find Hydro Sandbox Runtime Directory Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/hydrojudge.en.mdx Run this command on the server to locate the runtime directory of `hydro-sandbox` for pre-2022/8/12 installations. ```bash pm2 info hydro-sandbox | grep "exec cwd" ``` -------------------------------- ### GitHub OAuth Integration Example Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/third-party-auth.md This TypeScript code demonstrates how to implement GitHub OAuth for user login. It includes functions for initiating the OAuth flow and handling the callback from GitHub to exchange authorization codes for access tokens and user information. Ensure system settings for GitHub ID, secret, and endpoint are configured. ```typescript import { Context, ForbiddenError, Handler, superagent, SystemModel, TokenModel, UserFacingError, ValidationError, } from 'hydrooj'; declare module 'hydrooj' { interface SystemKeys { 'login-with-github.id': string; 'login-with-github.secret': string; 'login-with-github.endpoint': string; } } // 当用户点击 【使用 XX 登录】 按钮时,此函数会被执行 async function get(this: Handler) { // 从系统设置中获取基础设置,并储存状态信息(完成登录逻辑后应该跳转到哪一页) const [appid, [state]] = await Promise.all([ SystemModel.get('login-with-github.id'), TokenModel.add(TokenModel.TYPE_OAUTH, 600, { redirect: this.request.referer }), ]); // 将用户重定向至第三方平台请求授权。 this.response.redirect = `https://github.com/login/oauth/authorize?client_id=${appid}&state=${state}&scope=read:user,user:email`; } // 当用户在三方系统中完成授权,需要重定向到 /oauth/xxx/callback,这时所有返回的参数作为 callback 的一参数传入。 async function callback({ state, code }) { // 获取系统设置和之前的状态。 const [[appid, secret, endpoint, url], s] = await Promise.all([ SystemModel.getMany([ 'login-with-github.id', 'login-with-github.secret', 'login-with-github.endpoint', 'server.url', ]), TokenModel.get(state, TokenModel.TYPE_OAUTH), ]); if (!s) throw new ValidationError('token'); // 使用从 url 中返回的 token 请求第三方的 API,获取用户信息,作为函数返回。 // 在 OAuth 协议中,需要使用 state 和 code 换取 access_token 再调用 API,这在不同系统中可能设计不同。 // 系统会根据返回的用户信息自动查找已有用户或是创建新用户。 const res = await superagent.post(`${endpoint || 'https://github.com'}/login/oauth/access_token`) .send({ client_id: appid, client_secret: secret, code, redirect_uri: `${url}oauth/github/callback`, state, }) .set('accept', 'application/json'); if (res.body.error) { throw new UserFacingError( res.body.error, res.body.error_description, res.body.error_uri, ); } const t = res.body.access_token; const userInfo = await superagent.get(`${endpoint ? `${endpoint}/api` : 'https://api.github.com'}/user`) .set('User-Agent', 'Hydro-OAuth') .set('Accept', 'application/vnd.github.v3+json') .set('Authorization', `token ${t}`); const ret = { _id: `${userInfo.body.id}@github.local`, email: userInfo.body.email, bio: userInfo.body.bio, // 提供多个用户名,若需创建用户则从前往后尝试,直到用户名可用 uname: [userInfo.body.name, userInfo.body.login].filter((i) => i), avatar: `github:${userInfo.body.login}`, }; await TokenModel.del(s._id, TokenModel.TYPE_OAUTH); if (!ret.email) throw new ForbiddenError("You don't have a verified email."); return ret; } // 注册此模块。 export function apply(ctx: Context) { ctx.provideModule('oauth', 'github', { text: 'Login with Github', callback, get, }); ctx.i18n.load('zh', { 'Login With Github': '使用 Github 登录', }); } ``` -------------------------------- ### Manage Hydro Processes with PM2 Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/system/maintain.en.md Use these PM2 commands to list, start, stop, restart, and view logs for Hydro processes. Save the process list for auto-boot. ```bash pm2 ls # List all processes ``` ```bash pm2 start # Start a process ``` ```bash pm2 stop # Stop a process ``` ```bash pm2 restart # Restart a process ``` ```bash pm2 logs --lines 100 # View the last 100 log entries ``` ```bash pm2 save # Save current process list for auto-boot ``` ```bash pm2 resurrect # Manually restore a saved process list ``` -------------------------------- ### Install Local Plugin Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/index.en.mdx Add a plugin to Hydro using its absolute folder path. The specified path must contain the plugin's package.json file. ```sh hydrooj addon add /root/xxx ``` -------------------------------- ### Increase Program Stack Size Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/hydrojudge.en.mdx Modify hydro-sandbox startup arguments in pm2 to `ulimit -s unlimited`. Instances installed after 2022/8/12 have unlimited stack size by default. ```bash pm2 del hydro-sandbox pm2 start bash --name hydro-sandbox -- -c "ulimit -s unlimited && hydro-sandbox" ``` -------------------------------- ### Import Hydro Problems via CLI Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/user/problem.mdx Use this command to import Hydro-formatted problem packages from a file or directory into a specified domain. Ensure you have the Hydro CLI installed. ```bash hydrooj cli problem import ``` -------------------------------- ### Configure Language Time Limit Rate Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/compiler.en.mdx Example YAML configuration to set the time limit rate for Java. A rate of 2 means double the default time limit. ```yaml java: # ... existing settings ... time_limit_rate: 2 ``` -------------------------------- ### Initialize Plugin Project with Yarn Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/typescript.en.md Bootstrap a new plugin directory using yarn. Follow prompts to set up package details. ```bash mkdir hydro-pastebin && cd hydro-pastebin yarn init # Follow the prompts (e.g., @hydrooj/pastebin) ``` -------------------------------- ### Update Nix Channels and Install Packages Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/upgrade.md This command sequence updates your nix channels and installs necessary packages, including Node.js, Yarn, and PM2, to resolve NodeJS version issues. ```bash nix-channel --update nix-env -iA nixpkgs.nodejs nixpkgs.yarn nixpkgs.pm2 # 继续升级操作 yarn global upgrade-interactive --latest pm2 restart hydrooj --update-env ``` -------------------------------- ### Modify Sandbox Storage Size Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/hydrojudge.en.mdx For users installed after 2022/8/12, edit `/root/.hydro/mount.yaml` to adjust `size`. For older installations, create a `mount.yaml` in the runtime directory and modify `size` and `nr_inodes` for `work dir` and `tmp dir`. ```yaml size: "100G" nr_inodes: "100000" ``` -------------------------------- ### Build Production UI Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/index.en.mdx Build the production version of the frontend UI. This step requires a significant amount of RAM (around 8GB). ```bash yarn build:ui:production ``` -------------------------------- ### Backup Addon Configuration Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/debug.en.md Create a backup of the `addon.json` file before removing third-party plugins to troubleshoot HydroOJ crashes. ```bash cp ~/.hydro/addon.json ~/.hydro/addon.json.bak ``` -------------------------------- ### Uninstall HydroJudge Add-on Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/hydrojudge.en.mdx Run these commands to remove HydroJudge when installed as an add-on. ```sh yarn global remove @hydrooj/hydrojudge hydrooj addon remove @hydrooj/hydrojudge ``` -------------------------------- ### Restore Database from Backup File Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/system/database.mdx Use this command to restore your data from a previously created backup file. Replace `<备份文件路径>` with the actual path to your backup file. ```bash hydrooj restore <备份文件路径> ``` -------------------------------- ### Uninstall Plugin Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/plugins/index.en.mdx Remove a plugin from both the global yarn installation and Hydro's registered addons. ```sh yarn global remove @hydrooj/geoip hydrooj addon remove @hydrooj/geoip ``` -------------------------------- ### Check Hydro Version Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/system/maintain.en.md Navigate to the global yarn directory and list installed packages to check the Hydrooj version. ```bash cd $(yarn global dir) && yarn list --pattern hydrooj ``` -------------------------------- ### 启用非官方插件 Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/index.mdx 使用 yarn 命令启用位于指定路径下的非官方插件。例如,启用位于 `/root/addon` 目录下的插件。 ```sh yarn hydrooj addon add /root/addon ``` -------------------------------- ### Add Custom Plugin Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/index.en.mdx Enable a custom or third-party plugin by providing the absolute path to its directory. ```bash yarn hydrooj addon add /path/to/your/addon ``` -------------------------------- ### Download Mozjs Sources Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/riscv.en.mdx Navigates to the mozjs directory and downloads its sources using the provided script. ```bash cd src/third_party/mozjs bash get-sources.sh ``` -------------------------------- ### C++ File I/O Solution for File-Based Tests Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/user/problem-create.en.md This C++ program demonstrates file I/O for tests. It reads from 'test.in' and writes to 'test.out', suitable for configurations where input/output are file-based. ```cpp #include using namespace std; int main(int argc,char* argv[]){ int a,b; ifstream ifs("test.in"); ifs>>a>>b; ofstream ofs("test.out"); ofs <<(a+b); return 0; } ``` -------------------------------- ### Markdown for Sample Data Grouping Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/user/problem.en.mdx Demonstrates how to pair input and output test cases using numeric indices in Markdown for side-by-side display. ```markdown ```input1 1 2 ``` ```output1 3 ``` ``` -------------------------------- ### Markdown Table Merging Example Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/user/problem.mdx Demonstrates how Markdown tables can be merged. This feature helps in presenting complex data structures more compactly within the problem statement. ```markdown | 1 | 1 | 3 | 4 | 5 | | --- | --- | --- | --- | --- | | 1 | 1 | 2 | 2 | 6 | | 1 | 1 | 2 | 2 | 7 | | 1 | 4 | 3 | 5 | 5 | ``` -------------------------------- ### Enable Colored C/C++ Compilation Errors Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/compiler.en.mdx Example YAML configuration to append the flag for colored C/C++ compilation errors. Ensure your compiler supports this feature. ```yaml c: compile: /usr/bin/gcc -O2 -Wall -std=c99 -o ${name} foo.c -lm -fdiagnostics-color=always ``` -------------------------------- ### Backup and Restore Commands Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/index.en.mdx Use these commands for backing up and restoring data. Consider using crontab for automated backups. ```bash hydrooj backup ``` ```bash hydrooj restore backup-xxx.zip ``` -------------------------------- ### Promote User to Super Admin Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/install/index.en.mdx Use this CLI command to promote the first registered user to Super Admin. Replace '2' with the user ID if necessary. ```sh hydrooj cli user setSuperAdmin 2 ``` -------------------------------- ### Hydro.js Pastebin Plugin - Core Logic Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/typescript.en.md Defines the core data model, database interaction functions (add, get), and registers the pastebin model globally. ```typescript // @noErrors // @module: esnext // @filename: index.ts import { db, definePlugin, Handler, NotFoundError, randomstring, param, PermissionError, PRIV, Types, } from 'hydrooj'; const coll = db.collection('paste'); interface Paste { _id: string; owner: number; content: string; isPrivate: boolean; } declare module 'hydrooj' { interface Model { pastebin: typeof pastebinModel; } interface Collections { paste: Paste; // 声明数据表类型 } } async function add(userId: number, content: string, isPrivate: boolean): Promise { const pasteId = randomstring(16); // 使用 mongodb 为数据库驱动,相关操作参照其文档 const result = await coll.insertOne({ _id: pasteId, owner: userId, content, isPrivate, }); return result.insertedId; // 返回插入的文档ID } async function get(pasteId: string): Promise { return await coll.findOne({ _id: pasteId }); } // 暴露这些接口,使得 cli 也能够正常调用这些函数; const pastebinModel = { add, get }; global.Hydro.model.pastebin = pastebinModel; ``` -------------------------------- ### Hydro.js Plugin Development Flow Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/typescript.en.md Illustrates the sequence of function calls for handling requests in Hydro.js, including prepare, get, post, post[Operation], and cleanup. ```plaintext First execute prepare(args) (if present) args is the full set of incoming parameters (including QueryString, Body, Path), Then execute prepare(args) (if present) Check request type: Is it GET? -> Execute get(args) Is it POST? -> Execute post(args) -> Contains operation field? -> Execute post[Operation] Execute cleanup() ``` -------------------------------- ### Enable User Registration Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/FAQ/index.en.mdx Use this command to re-enable user registration by granting the PRIV_REGISTER_USER permission to the Guest user (uid 0). ```bash hydrooj cli user setPriv 0 8 ``` -------------------------------- ### 启动 Hydro 开发服务器 Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/index.mdx 使用 `yarn debug` 命令启动 Hydro,并可指定端口和启用热重载。同时,在后台运行 `yarn build:ui:dev` 以实现前端源码的实时转译。 ```sh yarn debug --port=2333 --watch ``` -------------------------------- ### Hydro.js Pastebin Plugin - PasteShowHandler Source: https://github.com/hydro-dev/hydro-dev.github.io/blob/docs/content/docs/Hydro/dev/typescript.en.md Handles GET requests to display a paste and POST requests for operations like deletion. Includes permission checks for private pastes. ```typescript class PasteShowHandler extends Handler { @param('id', Types.String) async get(domainId: string, id: string) { const doc = await pastebin.get(id); if (!doc) throw new NotFoundError(id); if (doc.isPrivate && this.user._id !== doc.owner) { throw new PermissionError(); } this.response.body = { doc }; this.response.template = 'paste_show.html'; } @param('id', Types.String) async postDelete(domainId: string, id: string) { // 当提交表单并存在 operation 值为 delete 时执行。 // 本例中未实现删除功能,仅作为说明。 } } ```