-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement Phase 2 Civitai Guard (v0.2) #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
882b47b
feat: implement allowlist cache and file watcher in Rust
MrBT-nano bbb0321
feat: enforce allowlist check in gRPC Generate method
MrBT-nano 2b7ca0a
feat: add Civitai model hash and NSFW verification in Python
MrBT-nano 41f5e3e
chore: add k8s deployment manifest with git-sync sidecar
MrBT-nano cedf9a8
style: fix clippy lints (Default impl and redundant pattern matching)
MrBT-nano 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: vtuber-image | ||
| namespace: vtuber-image | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app: vtuber-image | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: vtuber-image | ||
| spec: | ||
| containers: | ||
| - name: vtuber-image | ||
| image: echo-layer/vtuber-image:latest | ||
| ports: | ||
| - containerPort: 8083 | ||
| env: | ||
| - name: CONFIG_PATH | ||
| value: "/mnt/config" | ||
| - name: ALLOWLIST_FILENAME | ||
| value: "allowlist.json" | ||
| - name: S3_ENDPOINT_URL | ||
| value: "http://seaweedfs-s3:8333" | ||
| - name: COMFYUI_URL | ||
| value: "http://comfyui:8188" | ||
| volumeMounts: | ||
| - name: config-volume | ||
| mountPath: /mnt/config | ||
| readOnly: true | ||
|
|
||
| # git-sync Sidecar to sync vtuber-commons | ||
| - name: git-sync | ||
| image: registry.k8s.io/git-sync/git-sync:v4.2.3 | ||
| args: | ||
| - "--repo=https://github.com/echo-layer/vtuber-commons" | ||
| - "--branch=main" | ||
| - "--root=/mnt/config" | ||
| - "--dest=vtuber-commons" | ||
| - "--wait=60" | ||
| volumeMounts: | ||
| - name: config-volume | ||
| mountPath: /mnt/config | ||
|
|
||
| volumes: | ||
| - name: config-volume | ||
| emptyDir: {} |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
| use std::collections::HashMap; | ||
| use std::fs; | ||
| use std::path::Path; | ||
| use std::sync::{Arc, RwLock}; | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize, Clone)] | ||
| pub struct ModelEntry { | ||
| pub model_id: String, | ||
| pub hash: String, | ||
| pub license: String, | ||
| pub allow_nsfw: bool, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct GuardCache { | ||
| cache: Arc<RwLock<HashMap<String, ModelEntry>>>, | ||
| } | ||
|
|
||
| impl Default for GuardCache { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| impl GuardCache { | ||
| pub fn new() -> Self { | ||
| Self { | ||
| cache: Arc::new(RwLock::new(HashMap::new())), | ||
| } | ||
| } | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| pub fn load_from_file<P: AsRef<Path>>(&self, path: P) -> anyhow::Result<()> { | ||
| let content = fs::read_to_string(path)?; | ||
| let entries: Vec<ModelEntry> = serde_json::from_str(&content)?; | ||
|
|
||
| let mut cache = self | ||
| .cache | ||
| .write() | ||
| .map_err(|_| anyhow::anyhow!("Failed to acquire write lock"))?; | ||
| cache.clear(); | ||
| for entry in entries { | ||
| cache.insert(entry.model_id.clone(), entry); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn get_model(&self, model_id: &str) -> Option<ModelEntry> { | ||
| let cache = self.cache.read().ok()?; | ||
| cache.get(model_id).cloned() | ||
| } | ||
| } | ||
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 @@ | ||
| pub mod cache; |
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.
Uh oh!
There was an error while loading. Please reload this page.