File and folder sharing via public links. Users generate access links that work even for people without accounts. Supports optional password protection, expiration, and granular permissions. Follows hexagonal architecture throughout.
## Domain Entities
**Share** (`src/domain/entities/share.rs`) -- the core entity representing a shared resource:
```rust
pubstructShare{
pubid: String,// unique link identifier
pubitem_id: String,// ID of shared file or folder
pubitem_type: ShareItemType,// File or Folder
pubtoken: String,// unique token for public access
The entity has methods to validate expiration, verify passwords, increment the access counter, and modify properties (permissions, password, expiration).
Stores share link records in a JSON file. Supports queries and updates, search by ID/token/user, and pagination.
> **Note:** This repository stores *share link metadata* only (tokens, permissions, expiration). The actual file/folder content is accessed via `FileReadPort` / `FolderStoragePort` which use the blob storage model (PostgreSQL metadata + DedupService blobs).
2. Frontend sends a POST to `/api/shares/` with details (optional password, expiration, permissions).
3.`ShareService.create_shared_link()` validates data and verifies the item exists.
4. A unique token and access URL are generated.
5. The link is saved to the repository.
6. The URL and link details are returned.
### Accessing a Shared Resource
1. Someone opens a shared link (e.g., `http://oxicloud.example/api/s/{token}`).
2. Backend checks: valid token, not expired, password-protected or not.
3. If password-protected, the user is prompted.
4. Access counter increments.
5. Resource metadata is returned for display in the UI.
6. The user can access content according to the granted permissions.
## Security
**Password Protection** -- passwords are stored as hashes, not plaintext. Currently uses a simple hash but the design supports stronger algorithms like bcrypt.
**Expiration Control** -- links can be configured to expire automatically. The system checks expiration before granting access.
**Permission Control** -- granular permission model (read, write, reshare). Each operation validates permissions before allowing the action.
## Error Handling
```rust
pubenumShareServiceError{
#[error("Share not found: {0}")]
NotFound(String),
#[error("Item not found: {0}")]
ItemNotFound(String),
#[error("Access denied: {0}")]
AccessDenied(String),
#[error("Invalid password: {0}")]
InvalidPassword(String),
#[error("Share expired")]
Expired,
#[error("Repository error: {0}")]
Repository(String),
#[error("Invalid item type: {0}")]
InvalidItemType(String),
#[error("Validation error: {0}")]
Validation(String),
}
```
HTTP status code mapping:
-`NotFound` -> HTTP 404
-`PasswordRequired` -> HTTP 401 + metadata
-`Expired` -> HTTP 410 Gone
-`AccessDenied` -> HTTP 403
-`ValidationError` -> HTTP 400
## Future Enhancements
1.**Notifications** -- alert users when their shared resources are accessed
2.**Activity Log** -- detailed audit trail of who accessed what and when
3.**Usage Limits** -- max access count or bandwidth per shared link
4.**Advanced Statistics** -- detailed metrics on shared resource usage
5.**Alternative Persistence** -- database or cloud storage backends (same interface)
- **Share metadata** is stored in a local JSON file via `ShareFsRepository`. This is separate from the 100% blob storage model used for file content.
- **File/folder lookups** during share access go through `FileReadPort` / `FolderStoragePort`, which read metadata from PostgreSQL and content from the DedupService blob store.
- **Scalability**: for higher load, share metadata could be migrated to PostgreSQL using the same hexagonal architecture (implement `ShareRepository` with PgPool).