@kkuffour/solid-moderation-plugin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONFIG-GUIDE.md +49 -0
- package/DEVELOPMENT.md +129 -0
- package/ENV-VARIABLES.md +137 -0
- package/INSTALLATION.md +90 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +81 -0
- package/PRODUCTION.md +186 -0
- package/PUBLISHING.md +104 -0
- package/README.md +53 -0
- package/TESTING.md +64 -0
- package/components/components.jsonld +17 -0
- package/components/context.jsonld +211 -0
- package/config/context.jsonld +15 -0
- package/config/default.json +80 -0
- package/dist/ModerationConfig.d.ts +16 -0
- package/dist/ModerationConfig.d.ts.map +1 -0
- package/dist/ModerationConfig.js +18 -0
- package/dist/ModerationConfig.js.map +1 -0
- package/dist/ModerationConfig.jsonld +66 -0
- package/dist/ModerationMixin.d.ts +13 -0
- package/dist/ModerationMixin.d.ts.map +1 -0
- package/dist/ModerationMixin.js +136 -0
- package/dist/ModerationMixin.js.map +1 -0
- package/dist/ModerationMixin.jsonld +180 -0
- package/dist/ModerationOperationHandler.d.ts +16 -0
- package/dist/ModerationOperationHandler.d.ts.map +1 -0
- package/dist/ModerationOperationHandler.js +45 -0
- package/dist/ModerationOperationHandler.js.map +1 -0
- package/dist/ModerationOperationHandler.jsonld +140 -0
- package/dist/ModerationRecord.d.ts +20 -0
- package/dist/ModerationRecord.d.ts.map +1 -0
- package/dist/ModerationRecord.js +3 -0
- package/dist/ModerationRecord.js.map +1 -0
- package/dist/ModerationRecord.jsonld +59 -0
- package/dist/ModerationStore.d.ts +12 -0
- package/dist/ModerationStore.d.ts.map +1 -0
- package/dist/ModerationStore.js +37 -0
- package/dist/ModerationStore.js.map +1 -0
- package/dist/ModerationStore.jsonld +59 -0
- package/dist/components/components.jsonld +17 -0
- package/dist/components/context.jsonld +211 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/SightEngineProvider.d.ts +52 -0
- package/dist/providers/SightEngineProvider.d.ts.map +1 -0
- package/dist/providers/SightEngineProvider.js +302 -0
- package/dist/providers/SightEngineProvider.js.map +1 -0
- package/dist/providers/SightEngineProvider.jsonld +209 -0
- package/dist/util/GuardedStream.d.ts +33 -0
- package/dist/util/GuardedStream.d.ts.map +1 -0
- package/dist/util/GuardedStream.js +89 -0
- package/dist/util/GuardedStream.js.map +1 -0
- package/package.json +40 -0
- package/simple-test.json +7 -0
- package/src/ModerationConfig.ts +29 -0
- package/src/ModerationMixin.ts +153 -0
- package/src/ModerationOperationHandler.ts +64 -0
- package/src/ModerationRecord.ts +19 -0
- package/src/ModerationStore.ts +41 -0
- package/src/index.ts +6 -0
- package/src/providers/SightEngineProvider.ts +367 -0
- package/src/util/GuardedStream.ts +101 -0
- package/tsconfig.json +20 -0
package/CONFIG-GUIDE.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Configuration Guide
|
|
2
|
+
|
|
3
|
+
## Understanding the Configuration Files
|
|
4
|
+
|
|
5
|
+
### `config/default.json` (Production - Installed with npm)
|
|
6
|
+
- Located in `node_modules/@solid/moderation-plugin/config/default.json` after installation
|
|
7
|
+
- Contains the complete moderation setup with default thresholds
|
|
8
|
+
- Imported by users in their CSS config using: `"@solid/moderation-plugin:config/default.json"`
|
|
9
|
+
- **This is what production users import**
|
|
10
|
+
|
|
11
|
+
### `config-with-moderation.json` (Local Testing Only)
|
|
12
|
+
- Located in the plugin source directory
|
|
13
|
+
- Used for testing the plugin locally before publishing
|
|
14
|
+
- Points to local files, not npm package
|
|
15
|
+
- **Not included in npm package**
|
|
16
|
+
|
|
17
|
+
## For Production Users
|
|
18
|
+
|
|
19
|
+
When you install the plugin via npm, you create a config file in **your CSS project**:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
|
|
24
|
+
"import": [
|
|
25
|
+
"css:config/file.json",
|
|
26
|
+
"@solid/moderation-plugin:config/default.json"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then run:
|
|
32
|
+
```bash
|
|
33
|
+
export SIGHTENGINE_API_USER=your_api_user
|
|
34
|
+
export SIGHTENGINE_API_SECRET=your_api_secret
|
|
35
|
+
npx @solid/community-server -c config-with-moderation.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## For Local Development/Testing
|
|
39
|
+
|
|
40
|
+
When testing the plugin locally (before publishing):
|
|
41
|
+
|
|
42
|
+
1. Use `npm link` to link the local plugin
|
|
43
|
+
2. Use the `config-with-moderation.json` file in the plugin directory
|
|
44
|
+
3. Run CSS pointing to that config file
|
|
45
|
+
|
|
46
|
+
## Key Difference
|
|
47
|
+
|
|
48
|
+
- **Production**: Import `@solid/moderation-plugin:config/default.json` (from npm package)
|
|
49
|
+
- **Local Testing**: Use full path to `config-with-moderation.json` (from source directory)
|
package/DEVELOPMENT.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Development Notes
|
|
2
|
+
|
|
3
|
+
## Components.js Module Loading Issue
|
|
4
|
+
|
|
5
|
+
### Problem
|
|
6
|
+
Components.js cannot load modules via `npm link` due to symlink resolution issues. When using `npm link`, the plugin appears in `node_modules/@solid/moderation-plugin` as a symlink, but Components.js's module loader cannot follow it to instantiate classes.
|
|
7
|
+
|
|
8
|
+
### Symptoms
|
|
9
|
+
- Server starts without errors
|
|
10
|
+
- Config file is loaded successfully
|
|
11
|
+
- No moderation logs appear when uploading files
|
|
12
|
+
- ModerationOperationHandler is never instantiated
|
|
13
|
+
- Uploads succeed without any moderation checks
|
|
14
|
+
|
|
15
|
+
### Root Cause
|
|
16
|
+
Components.js uses its own module resolution that doesn't properly handle symlinked packages. The `requireElement` in the generated `.jsonld` files points to the class name, but Components.js cannot resolve the actual module path through the symlink.
|
|
17
|
+
|
|
18
|
+
### Solutions
|
|
19
|
+
|
|
20
|
+
#### Option 1: File Path Dependency (Recommended for Development)
|
|
21
|
+
Add to CSS's `package.json`:
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@solid/moderation-plugin": "file:../solid-moderation"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then run:
|
|
31
|
+
```bash
|
|
32
|
+
cd /Users/opendata/CommunitySolidServer
|
|
33
|
+
npm install
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This creates a proper copy (not symlink) in node_modules.
|
|
37
|
+
|
|
38
|
+
**After code changes:**
|
|
39
|
+
```bash
|
|
40
|
+
cd /Users/opendata/solid-moderation
|
|
41
|
+
npm run build
|
|
42
|
+
cd /Users/opendata/CommunitySolidServer
|
|
43
|
+
npm install # Re-copies the updated files
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### Option 2: Publish to npm (Recommended for Production)
|
|
47
|
+
```bash
|
|
48
|
+
cd /Users/opendata/solid-moderation
|
|
49
|
+
npm publish
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Then in CSS:
|
|
53
|
+
```bash
|
|
54
|
+
npm install @solid/moderation-plugin@latest
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Option 3: Manual Copy (Quick Testing Only)
|
|
58
|
+
```bash
|
|
59
|
+
rm -rf /Users/opendata/CommunitySolidServer/node_modules/@solid/moderation-plugin
|
|
60
|
+
cp -r /Users/opendata/solid-moderation /Users/opendata/CommunitySolidServer/node_modules/@solid/moderation-plugin
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Note:** Must repeat after every code change.
|
|
64
|
+
|
|
65
|
+
## Current Configuration
|
|
66
|
+
|
|
67
|
+
### Environment Variables
|
|
68
|
+
```bash
|
|
69
|
+
export SIGHTENGINE_API_USER="1060049443"
|
|
70
|
+
export SIGHTENGINE_API_SECRET="QRQ8HUmh4hyvhZjksBJq5ZaNYPLPEKXu"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Thresholds (Configurable in config-with-moderation.json)
|
|
74
|
+
- **Image Nudity**: 0.1 (10% - very strict)
|
|
75
|
+
- **Text Sexual**: 0.1 (10% - very strict)
|
|
76
|
+
- **Text Toxic**: 0.1 (10% - very strict)
|
|
77
|
+
- **Video Nudity**: 0.1 (10% - very strict)
|
|
78
|
+
|
|
79
|
+
Lower values = stricter moderation (blocks more content)
|
|
80
|
+
Higher values = lenient moderation (blocks less content)
|
|
81
|
+
Range: 0.0 (block everything) to 1.0 (block nothing)
|
|
82
|
+
|
|
83
|
+
### Starting the Server
|
|
84
|
+
```bash
|
|
85
|
+
cd /Users/opendata/CommunitySolidServer
|
|
86
|
+
export SIGHTENGINE_API_USER="1060049443"
|
|
87
|
+
export SIGHTENGINE_API_SECRET="QRQ8HUmh4hyvhZjksBJq5ZaNYPLPEKXu"
|
|
88
|
+
npm start -- -c /Users/opendata/solid-moderation/config-with-moderation.json -f data/ -p 3009 -l debug > logs/server.log 2>&1 &
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Checking Logs
|
|
92
|
+
```bash
|
|
93
|
+
# Watch for moderation activity
|
|
94
|
+
tail -f logs/server.log | grep -i moderation
|
|
95
|
+
|
|
96
|
+
# Check if handler is invoked
|
|
97
|
+
grep "MODERATION: Checking" logs/server.log
|
|
98
|
+
|
|
99
|
+
# Check for API failures
|
|
100
|
+
grep "MODERATION:.*failed" logs/server.log
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Features Implemented
|
|
104
|
+
|
|
105
|
+
### Code Structure
|
|
106
|
+
- **ModerationOperationHandler**: Wraps POST/PUT/PATCH handlers
|
|
107
|
+
- **ModerationMixin**: Performs actual content checks
|
|
108
|
+
- **ModerationStore**: Audit logging for violations
|
|
109
|
+
- **SightEngineProvider**: API client for SightEngine
|
|
110
|
+
- **Configurable thresholds**: All thresholds adjustable via config
|
|
111
|
+
|
|
112
|
+
### Moderation Checks
|
|
113
|
+
- **Images**: Nudity detection
|
|
114
|
+
- **Text**: Sexual content and toxic language
|
|
115
|
+
- **Video**: Nudity detection
|
|
116
|
+
- **Fail-open policy**: Allows content if API fails
|
|
117
|
+
|
|
118
|
+
### Debug Logging
|
|
119
|
+
- Handler invocation logs
|
|
120
|
+
- Content type detection logs
|
|
121
|
+
- API response with scores
|
|
122
|
+
- Threshold comparison logs
|
|
123
|
+
- Failure reason logs
|
|
124
|
+
|
|
125
|
+
## Known Issues
|
|
126
|
+
|
|
127
|
+
1. **npm link doesn't work** - Use file path dependency instead
|
|
128
|
+
2. **Environment variables** - Must be set before starting server
|
|
129
|
+
3. **Audit logs** - Only record violations, not all checks
|
package/ENV-VARIABLES.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Environment Variables Explained
|
|
2
|
+
|
|
3
|
+
## What `export` Does
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
export SIGHTENGINE_API_USER=your_api_user
|
|
7
|
+
export SIGHTENGINE_API_SECRET=your_api_secret
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
These commands set **environment variables** in your shell session:
|
|
11
|
+
|
|
12
|
+
- `export` makes the variable available to all programs you run in that terminal
|
|
13
|
+
- `SIGHTENGINE_API_USER` is the variable name
|
|
14
|
+
- `your_api_user` is the value (replace with your actual API credentials)
|
|
15
|
+
|
|
16
|
+
## How the Plugin Uses These Variables
|
|
17
|
+
|
|
18
|
+
In `config/default.json`, you'll see:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
"ModerationConfig:_sightEngine": {
|
|
22
|
+
"ModerationConfig:_sightEngine_apiUser": "${SIGHTENGINE_API_USER}",
|
|
23
|
+
"ModerationConfig:_sightEngine_apiSecret": "${SIGHTENGINE_API_SECRET}"
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The `${SIGHTENGINE_API_USER}` syntax means:
|
|
28
|
+
- "Look for an environment variable named SIGHTENGINE_API_USER"
|
|
29
|
+
- "Replace this placeholder with its value"
|
|
30
|
+
|
|
31
|
+
## Example Flow
|
|
32
|
+
|
|
33
|
+
1. **You set the variables:**
|
|
34
|
+
```bash
|
|
35
|
+
export SIGHTENGINE_API_USER=abc123
|
|
36
|
+
export SIGHTENGINE_API_SECRET=xyz789
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
2. **You start CSS:**
|
|
40
|
+
```bash
|
|
41
|
+
npx @solid/community-server -c config.json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. **The plugin reads the config and replaces placeholders:**
|
|
45
|
+
- `${SIGHTENGINE_API_USER}` becomes `abc123`
|
|
46
|
+
- `${SIGHTENGINE_API_SECRET}` becomes `xyz789`
|
|
47
|
+
|
|
48
|
+
4. **The plugin uses these credentials to call SightEngine API**
|
|
49
|
+
|
|
50
|
+
## Why Use Environment Variables?
|
|
51
|
+
|
|
52
|
+
✅ **Security**: Credentials aren't stored in config files (which might be committed to git)
|
|
53
|
+
✅ **Flexibility**: Different credentials for dev/staging/production without changing code
|
|
54
|
+
✅ **Standard Practice**: Common pattern for managing secrets
|
|
55
|
+
|
|
56
|
+
## Alternative Methods
|
|
57
|
+
|
|
58
|
+
### Option 1: Set per command (temporary)
|
|
59
|
+
```bash
|
|
60
|
+
SIGHTENGINE_API_USER=abc123 SIGHTENGINE_API_SECRET=xyz789 npx @solid/community-server -c config.json
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Option 2: Use a .env file (with dotenv)
|
|
64
|
+
Create `.env` file:
|
|
65
|
+
```
|
|
66
|
+
SIGHTENGINE_API_USER=abc123
|
|
67
|
+
SIGHTENGINE_API_SECRET=xyz789
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Option 3: Set in shell profile (permanent) ⭐ RECOMMENDED FOR PRODUCTION
|
|
71
|
+
Add to `~/.bashrc` or `~/.zshrc`:
|
|
72
|
+
```bash
|
|
73
|
+
export SIGHTENGINE_API_USER=abc123
|
|
74
|
+
export SIGHTENGINE_API_SECRET=xyz789
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Option 4: System service environment file (for systemd)
|
|
78
|
+
Create `/etc/systemd/system/solid-server.service.d/override.conf`:
|
|
79
|
+
```ini
|
|
80
|
+
[Service]
|
|
81
|
+
Environment="SIGHTENGINE_API_USER=abc123"
|
|
82
|
+
Environment="SIGHTENGINE_API_SECRET=xyz789"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## What Happens on Server Restart?
|
|
86
|
+
|
|
87
|
+
### ❌ If you only used `export` in terminal:
|
|
88
|
+
- Variables are **LOST** when terminal closes or server restarts
|
|
89
|
+
- Server will fail to moderate content (falls back to fail-open policy)
|
|
90
|
+
- You must re-export before starting server again
|
|
91
|
+
|
|
92
|
+
### ✅ If you added to shell profile (`~/.bashrc` or `~/.zshrc`):
|
|
93
|
+
- Variables are **PRESERVED** across terminal sessions
|
|
94
|
+
- But still lost on full system reboot unless server auto-starts with those variables
|
|
95
|
+
|
|
96
|
+
### ✅ If you use systemd service file:
|
|
97
|
+
- Variables are **ALWAYS AVAILABLE** to the service
|
|
98
|
+
- Survives server restarts and system reboots
|
|
99
|
+
- **BEST for production servers**
|
|
100
|
+
|
|
101
|
+
### ✅ If you use Docker:
|
|
102
|
+
```yaml
|
|
103
|
+
services:
|
|
104
|
+
solid-server:
|
|
105
|
+
environment:
|
|
106
|
+
- SIGHTENGINE_API_USER=abc123
|
|
107
|
+
- SIGHTENGINE_API_SECRET=xyz789
|
|
108
|
+
```
|
|
109
|
+
Variables are preserved in container configuration.
|
|
110
|
+
|
|
111
|
+
## Production Recommendation
|
|
112
|
+
|
|
113
|
+
For a production server that needs to survive restarts:
|
|
114
|
+
|
|
115
|
+
1. **Use systemd service** with environment variables in service file
|
|
116
|
+
2. **Or use Docker** with environment variables in docker-compose.yml
|
|
117
|
+
3. **Or use a process manager** like PM2 with ecosystem.config.js:
|
|
118
|
+
```javascript
|
|
119
|
+
module.exports = {
|
|
120
|
+
apps: [{
|
|
121
|
+
name: 'solid-server',
|
|
122
|
+
script: 'npx',
|
|
123
|
+
args: '@solid/community-server -c config.json',
|
|
124
|
+
env: {
|
|
125
|
+
SIGHTENGINE_API_USER: 'abc123',
|
|
126
|
+
SIGHTENGINE_API_SECRET: 'xyz789'
|
|
127
|
+
}
|
|
128
|
+
}]
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Getting Your API Credentials
|
|
133
|
+
|
|
134
|
+
1. Sign up at https://sightengine.com/
|
|
135
|
+
2. Go to your dashboard
|
|
136
|
+
3. Find your API User and API Secret
|
|
137
|
+
4. Replace `your_api_user` and `your_api_secret` with those values
|
package/INSTALLATION.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Files Generated in Community Solid Server
|
|
2
|
+
|
|
3
|
+
When you install `@solid/moderation-plugin` in your Community Solid Server, the following files will be generated in `node_modules/@solid/moderation-plugin/`:
|
|
4
|
+
|
|
5
|
+
## Directory Structure
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
node_modules/@solid/moderation-plugin/
|
|
9
|
+
├── dist/ # Compiled JavaScript and metadata
|
|
10
|
+
│ ├── components/ # Components.js metadata
|
|
11
|
+
│ │ ├── components.jsonld # Component definitions
|
|
12
|
+
│ │ └── context.jsonld # JSON-LD context
|
|
13
|
+
│ │
|
|
14
|
+
│ ├── providers/ # API providers
|
|
15
|
+
│ │ ├── SightEngineProvider.js
|
|
16
|
+
│ │ ├── SightEngineProvider.d.ts
|
|
17
|
+
│ │ ├── SightEngineProvider.js.map
|
|
18
|
+
│ │ ├── SightEngineProvider.d.ts.map
|
|
19
|
+
│ │ └── SightEngineProvider.jsonld
|
|
20
|
+
│ │
|
|
21
|
+
│ ├── util/ # Utilities
|
|
22
|
+
│ │ ├── GuardedStream.js
|
|
23
|
+
│ │ ├── GuardedStream.d.ts
|
|
24
|
+
│ │ └── *.map files
|
|
25
|
+
│ │
|
|
26
|
+
│ ├── index.js # Main entry point
|
|
27
|
+
│ ├── index.d.ts # TypeScript definitions
|
|
28
|
+
│ ├── ModerationOperationHandler.js
|
|
29
|
+
│ ├── ModerationOperationHandler.d.ts
|
|
30
|
+
│ ├── ModerationOperationHandler.jsonld
|
|
31
|
+
│ ├── ModerationConfig.js
|
|
32
|
+
│ ├── ModerationConfig.d.ts
|
|
33
|
+
│ ├── ModerationConfig.jsonld
|
|
34
|
+
│ ├── ModerationStore.js
|
|
35
|
+
│ ├── ModerationStore.d.ts
|
|
36
|
+
│ ├── ModerationStore.jsonld
|
|
37
|
+
│ ├── ModerationMixin.js
|
|
38
|
+
│ ├── ModerationMixin.d.ts
|
|
39
|
+
│ ├── ModerationMixin.jsonld
|
|
40
|
+
│ ├── ModerationRecord.js
|
|
41
|
+
│ ├── ModerationRecord.d.ts
|
|
42
|
+
│ ├── ModerationRecord.jsonld
|
|
43
|
+
│ └── *.map files # Source maps
|
|
44
|
+
│
|
|
45
|
+
├── config/ # Configuration templates
|
|
46
|
+
│ └── default.json # Default moderation settings
|
|
47
|
+
│
|
|
48
|
+
├── package.json # Package metadata
|
|
49
|
+
├── README.md # Documentation
|
|
50
|
+
└── LICENSE # MIT License
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Runtime Files (Created During Operation)
|
|
54
|
+
|
|
55
|
+
When CSS runs with moderation enabled, these files/folders are created:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
your-css-project/
|
|
59
|
+
├── data/
|
|
60
|
+
│ └── moderation-logs/ # Audit logs (if enabled)
|
|
61
|
+
│ ├── 2024-01-20.jsonl # Daily log files
|
|
62
|
+
│ ├── 2024-01-21.jsonl
|
|
63
|
+
│ └── ...
|
|
64
|
+
│
|
|
65
|
+
└── /tmp/ # Temporary files during analysis
|
|
66
|
+
└── moderation_*.jpg/mp4 # Auto-deleted after analysis
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Key Files Explained
|
|
70
|
+
|
|
71
|
+
### Components.js Files (*.jsonld)
|
|
72
|
+
- Used by CSS's dependency injection system
|
|
73
|
+
- Define how classes are instantiated and wired together
|
|
74
|
+
- Allow configuration through JSON-LD config files
|
|
75
|
+
|
|
76
|
+
### JavaScript Files (*.js)
|
|
77
|
+
- Compiled TypeScript code
|
|
78
|
+
- Main application logic
|
|
79
|
+
|
|
80
|
+
### TypeScript Definitions (*.d.ts)
|
|
81
|
+
- Type information for TypeScript users
|
|
82
|
+
- Enable IDE autocomplete and type checking
|
|
83
|
+
|
|
84
|
+
### Source Maps (*.map)
|
|
85
|
+
- Map compiled JS back to original TypeScript
|
|
86
|
+
- Used for debugging
|
|
87
|
+
|
|
88
|
+
### config/default.json
|
|
89
|
+
- Template configuration with default thresholds
|
|
90
|
+
- Can be imported in CSS config files
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/MIGRATION.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Migration Guide: Extracting Moderation to External Plugin
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This guide walks through migrating the moderation feature from CSS core to the standalone `@solid/moderation-plugin` package.
|
|
6
|
+
|
|
7
|
+
## Steps
|
|
8
|
+
|
|
9
|
+
### 1. Publish Plugin Package
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
cd mod-package-struct
|
|
13
|
+
npm install
|
|
14
|
+
npm run build
|
|
15
|
+
npm publish --access public
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### 2. Update CSS to Use Plugin
|
|
19
|
+
|
|
20
|
+
In your CSS project:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @solid/moderation-plugin
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 3. Update Configuration
|
|
27
|
+
|
|
28
|
+
Replace `config/file-moderation.json` with:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
|
|
33
|
+
"import": [
|
|
34
|
+
"css:config/file.json",
|
|
35
|
+
"@solid/moderation-plugin:config/default.json"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 4. Remove Core Moderation Code
|
|
41
|
+
|
|
42
|
+
Delete from CSS repository:
|
|
43
|
+
- `src/moderation/` directory
|
|
44
|
+
- `src/http/ldp/ModerationOperationHandler.ts`
|
|
45
|
+
- `src/http/ldp/ModerationMixin.ts`
|
|
46
|
+
- `config/moderation-settings.json`
|
|
47
|
+
- `config/file-moderation.json`
|
|
48
|
+
|
|
49
|
+
### 5. Update Exports
|
|
50
|
+
|
|
51
|
+
Remove from `src/index.ts`:
|
|
52
|
+
- ModerationOperationHandler export
|
|
53
|
+
- ModerationConfig export
|
|
54
|
+
- ModerationStore export
|
|
55
|
+
- ModerationMixin export
|
|
56
|
+
|
|
57
|
+
### 6. Test
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Start server with plugin
|
|
61
|
+
npm start -- -c config-with-moderation.json
|
|
62
|
+
|
|
63
|
+
# Test image upload
|
|
64
|
+
curl -X PUT http://localhost:3000/test.jpg \
|
|
65
|
+
-H "Content-Type: image/jpeg" \
|
|
66
|
+
--data-binary @test-image.jpg
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Rollback Plan
|
|
70
|
+
|
|
71
|
+
If issues occur:
|
|
72
|
+
1. Keep plugin package unpublished
|
|
73
|
+
2. Revert CSS changes
|
|
74
|
+
3. Continue using embedded moderation
|
|
75
|
+
|
|
76
|
+
## Timeline
|
|
77
|
+
|
|
78
|
+
- Week 1: Extract and test plugin locally
|
|
79
|
+
- Week 2: Publish plugin to npm
|
|
80
|
+
- Week 3: Update CSS to use plugin
|
|
81
|
+
- Week 4: Remove core moderation code
|
package/PRODUCTION.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Production Deployment Guide
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
1. **Install the plugin:**
|
|
6
|
+
```bash
|
|
7
|
+
npm install @solid/moderation-plugin
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
2. **Create config file** in your CSS project (e.g., `config-with-moderation.json`):
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"@context": [
|
|
14
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
|
|
15
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/moderation-plugin/^1.0.0/components/context.jsonld"
|
|
16
|
+
],
|
|
17
|
+
"import": [
|
|
18
|
+
"css:config/file.json",
|
|
19
|
+
"@solid/moderation-plugin:config/default.json"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
3. **Set environment variables** (choose one method):
|
|
25
|
+
|
|
26
|
+
## Environment Variable Setup
|
|
27
|
+
|
|
28
|
+
### Option 1: Shell Profile (Simple)
|
|
29
|
+
Add to `~/.bashrc` or `~/.zshrc`:
|
|
30
|
+
```bash
|
|
31
|
+
export SIGHTENGINE_API_USER=your_api_user
|
|
32
|
+
export SIGHTENGINE_API_SECRET=your_api_secret
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Option 2: Systemd Service (Recommended for Production)
|
|
36
|
+
Create `/etc/systemd/system/solid-server.service`:
|
|
37
|
+
```ini
|
|
38
|
+
[Unit]
|
|
39
|
+
Description=Community Solid Server with Moderation
|
|
40
|
+
After=network.target
|
|
41
|
+
|
|
42
|
+
[Service]
|
|
43
|
+
Type=simple
|
|
44
|
+
User=solid
|
|
45
|
+
WorkingDirectory=/opt/solid-server
|
|
46
|
+
Environment="SIGHTENGINE_API_USER=your_api_user"
|
|
47
|
+
Environment="SIGHTENGINE_API_SECRET=your_api_secret"
|
|
48
|
+
ExecStart=/usr/bin/npx @solid/community-server -c config-with-moderation.json
|
|
49
|
+
Restart=always
|
|
50
|
+
|
|
51
|
+
[Install]
|
|
52
|
+
WantedBy=multi-user.target
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Enable and start:
|
|
56
|
+
```bash
|
|
57
|
+
sudo systemctl enable solid-server
|
|
58
|
+
sudo systemctl start solid-server
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Option 3: Docker
|
|
62
|
+
Create `docker-compose.yml`:
|
|
63
|
+
```yaml
|
|
64
|
+
version: '3'
|
|
65
|
+
services:
|
|
66
|
+
solid-server:
|
|
67
|
+
image: node:20
|
|
68
|
+
working_dir: /app
|
|
69
|
+
volumes:
|
|
70
|
+
- ./:/app
|
|
71
|
+
environment:
|
|
72
|
+
- SIGHTENGINE_API_USER=your_api_user
|
|
73
|
+
- SIGHTENGINE_API_SECRET=your_api_secret
|
|
74
|
+
command: npx @solid/community-server -c config-with-moderation.json
|
|
75
|
+
ports:
|
|
76
|
+
- "3000:3000"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Run:
|
|
80
|
+
```bash
|
|
81
|
+
docker-compose up -d
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Option 4: PM2 Process Manager
|
|
85
|
+
Create `ecosystem.config.js`:
|
|
86
|
+
```javascript
|
|
87
|
+
module.exports = {
|
|
88
|
+
apps: [{
|
|
89
|
+
name: 'solid-server',
|
|
90
|
+
script: 'npx',
|
|
91
|
+
args: '@solid/community-server -c config-with-moderation.json',
|
|
92
|
+
env: {
|
|
93
|
+
SIGHTENGINE_API_USER: 'your_api_user',
|
|
94
|
+
SIGHTENGINE_API_SECRET: 'your_api_secret'
|
|
95
|
+
}
|
|
96
|
+
}]
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Run:
|
|
101
|
+
```bash
|
|
102
|
+
pm2 start ecosystem.config.js
|
|
103
|
+
pm2 save
|
|
104
|
+
pm2 startup
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## How It Works in Production
|
|
108
|
+
|
|
109
|
+
### Local Testing vs Production
|
|
110
|
+
|
|
111
|
+
| Aspect | Local Testing | Production |
|
|
112
|
+
|--------|--------------|------------|
|
|
113
|
+
| Plugin Location | `/Users/opendata/solid-moderation` (source) | `node_modules/@solid/moderation-plugin` (npm) |
|
|
114
|
+
| Installation | `npm link` | `npm install @solid/moderation-plugin` |
|
|
115
|
+
| Config Import | Full path to local file | `@solid/moderation-plugin:config/default.json` |
|
|
116
|
+
| Components | Loaded from local `dist/` | Loaded from `node_modules/@solid/moderation-plugin/dist/` |
|
|
117
|
+
|
|
118
|
+
### What Happens When CSS Starts
|
|
119
|
+
|
|
120
|
+
1. **CSS reads your config file**
|
|
121
|
+
2. **Sees import:** `@solid/moderation-plugin:config/default.json`
|
|
122
|
+
3. **Resolves to:** `node_modules/@solid/moderation-plugin/config/default.json`
|
|
123
|
+
4. **Loads components from:** `node_modules/@solid/moderation-plugin/dist/components/`
|
|
124
|
+
5. **Instantiates:** ModerationOperationHandler wrapping PUT/POST/PATCH
|
|
125
|
+
6. **Reads env vars:** `${SIGHTENGINE_API_USER}` → actual value
|
|
126
|
+
7. **Server starts** with moderation active
|
|
127
|
+
|
|
128
|
+
### File Locations in Production
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
your-css-project/
|
|
132
|
+
├── node_modules/
|
|
133
|
+
│ └── @solid/
|
|
134
|
+
│ └── moderation-plugin/ ← Installed here
|
|
135
|
+
│ ├── dist/
|
|
136
|
+
│ │ ├── components/
|
|
137
|
+
│ │ ├── *.js
|
|
138
|
+
│ │ └── *.jsonld
|
|
139
|
+
│ ├── config/
|
|
140
|
+
│ │ └── default.json ← Imported by your config
|
|
141
|
+
│ └── package.json
|
|
142
|
+
│
|
|
143
|
+
├── config-with-moderation.json ← Your config file
|
|
144
|
+
├── data/
|
|
145
|
+
│ └── moderation-logs/ ← Runtime logs
|
|
146
|
+
└── package.json
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Customizing Thresholds in Production
|
|
150
|
+
|
|
151
|
+
Override specific settings in your config:
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"import": [
|
|
155
|
+
"css:config/file.json",
|
|
156
|
+
"@solid/moderation-plugin:config/default.json"
|
|
157
|
+
],
|
|
158
|
+
"@graph": [
|
|
159
|
+
{
|
|
160
|
+
"@id": "urn:solid-moderation:default:Config",
|
|
161
|
+
"ModerationConfig:_images_thresholds": {
|
|
162
|
+
"ModerationConfig:_images_thresholds_nudity": 0.3
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Monitoring
|
|
170
|
+
|
|
171
|
+
Check logs:
|
|
172
|
+
```bash
|
|
173
|
+
# Systemd
|
|
174
|
+
sudo journalctl -u solid-server -f
|
|
175
|
+
|
|
176
|
+
# PM2
|
|
177
|
+
pm2 logs solid-server
|
|
178
|
+
|
|
179
|
+
# Docker
|
|
180
|
+
docker-compose logs -f
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
View moderation violations:
|
|
184
|
+
```bash
|
|
185
|
+
cat data/moderation-logs/$(date +%Y-%m-%d).jsonl
|
|
186
|
+
```
|