Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
58
native/desktop/maplefile/internal/domain/file/constants.go
Normal file
58
native/desktop/maplefile/internal/domain/file/constants.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package file
|
||||
|
||||
// SyncStatus defines the synchronization status of a file
|
||||
type SyncStatus int
|
||||
|
||||
const (
|
||||
// SyncStatusLocalOnly indicates the file exists only locally (not uploaded to cloud)
|
||||
SyncStatusLocalOnly SyncStatus = iota
|
||||
|
||||
// SyncStatusCloudOnly indicates the file exists only in the cloud (metadata synced, content not downloaded)
|
||||
SyncStatusCloudOnly
|
||||
|
||||
// SyncStatusSynced indicates the file exists both locally and in the cloud and is synchronized
|
||||
SyncStatusSynced
|
||||
|
||||
// SyncStatusModifiedLocally indicates the file exists in both places but has local changes pending upload
|
||||
SyncStatusModifiedLocally
|
||||
)
|
||||
|
||||
// String returns a human-readable string representation of the sync status
|
||||
func (s SyncStatus) String() string {
|
||||
switch s {
|
||||
case SyncStatusLocalOnly:
|
||||
return "local_only"
|
||||
case SyncStatusCloudOnly:
|
||||
return "cloud_only"
|
||||
case SyncStatusSynced:
|
||||
return "synced"
|
||||
case SyncStatusModifiedLocally:
|
||||
return "modified_locally"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// Storage mode constants define which file versions to keep locally
|
||||
const (
|
||||
// StorageModeEncryptedOnly - Only keep encrypted version locally (most secure)
|
||||
StorageModeEncryptedOnly = "encrypted_only"
|
||||
|
||||
// StorageModeDecryptedOnly - Only keep decrypted version locally (not recommended)
|
||||
StorageModeDecryptedOnly = "decrypted_only"
|
||||
|
||||
// StorageModeHybrid - Keep both encrypted and decrypted versions (default, convenient)
|
||||
StorageModeHybrid = "hybrid"
|
||||
)
|
||||
|
||||
// File state constants
|
||||
const (
|
||||
// StatePending is the initial state of a file before it is uploaded
|
||||
StatePending = "pending"
|
||||
|
||||
// StateActive indicates that the file is fully uploaded and ready for use
|
||||
StateActive = "active"
|
||||
|
||||
// StateDeleted marks the file as deleted
|
||||
StateDeleted = "deleted"
|
||||
)
|
||||
28
native/desktop/maplefile/internal/domain/file/interface.go
Normal file
28
native/desktop/maplefile/internal/domain/file/interface.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package file
|
||||
|
||||
// Repository defines the data access operations for files
|
||||
type Repository interface {
|
||||
// Create stores a new file record
|
||||
Create(file *File) error
|
||||
|
||||
// Get retrieves a file by its ID
|
||||
Get(id string) (*File, error)
|
||||
|
||||
// Update modifies an existing file record
|
||||
Update(file *File) error
|
||||
|
||||
// Delete removes a file record by its ID
|
||||
Delete(id string) error
|
||||
|
||||
// List returns all file records
|
||||
List() ([]*File, error)
|
||||
|
||||
// ListByCollection returns all files belonging to a specific collection
|
||||
ListByCollection(collectionID string) ([]*File, error)
|
||||
|
||||
// ListByStatus returns all files with a specific sync status
|
||||
ListByStatus(status SyncStatus) ([]*File, error)
|
||||
|
||||
// Exists checks if a file with the given ID exists
|
||||
Exists(id string) (bool, error)
|
||||
}
|
||||
88
native/desktop/maplefile/internal/domain/file/model.go
Normal file
88
native/desktop/maplefile/internal/domain/file/model.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
package file
|
||||
|
||||
import "time"
|
||||
|
||||
// File represents a file stored locally with sync capabilities.
|
||||
// This model combines cloud metadata with local storage tracking.
|
||||
type File struct {
|
||||
// Identifiers (from cloud)
|
||||
ID string `json:"id"`
|
||||
CollectionID string `json:"collection_id"`
|
||||
OwnerID string `json:"owner_id"` // UserID from cloud
|
||||
|
||||
// Encryption data (from cloud API response)
|
||||
EncryptedFileKey EncryptedFileKeyData `json:"encrypted_file_key"`
|
||||
FileKeyNonce string `json:"file_key_nonce"`
|
||||
EncryptedMetadata string `json:"encrypted_metadata"`
|
||||
MetadataNonce string `json:"metadata_nonce"`
|
||||
FileNonce string `json:"file_nonce"`
|
||||
|
||||
// File sizes (from cloud)
|
||||
EncryptedSizeInBytes int64 `json:"encrypted_file_size_in_bytes"`
|
||||
DecryptedSizeInBytes int64 `json:"decrypted_size_in_bytes,omitempty"`
|
||||
|
||||
// Local storage paths (local only)
|
||||
EncryptedFilePath string `json:"encrypted_file_path,omitempty"`
|
||||
FilePath string `json:"file_path,omitempty"`
|
||||
ThumbnailPath string `json:"thumbnail_path,omitempty"`
|
||||
|
||||
// Decrypted metadata (local only - populated after decryption)
|
||||
Name string `json:"name,omitempty"`
|
||||
MimeType string `json:"mime_type,omitempty"`
|
||||
Metadata *FileMetadata `json:"metadata,omitempty"`
|
||||
|
||||
// Sync tracking (local only)
|
||||
SyncStatus SyncStatus `json:"sync_status"`
|
||||
LastSyncedAt time.Time `json:"last_synced_at,omitempty"`
|
||||
|
||||
// State from cloud
|
||||
State string `json:"state"` // pending, active, deleted
|
||||
StorageMode string `json:"storage_mode"` // encrypted_only, hybrid, decrypted_only
|
||||
Version int `json:"version"` // Cloud version for conflict resolution
|
||||
|
||||
// Timestamps (from cloud)
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ModifiedAt time.Time `json:"modified_at"`
|
||||
|
||||
// Thumbnail URL (from cloud, for remote access)
|
||||
ThumbnailURL string `json:"thumbnail_url,omitempty"`
|
||||
}
|
||||
|
||||
// EncryptedFileKeyData matches the cloud API structure exactly
|
||||
type EncryptedFileKeyData struct {
|
||||
Ciphertext string `json:"ciphertext"`
|
||||
Nonce string `json:"nonce"`
|
||||
}
|
||||
|
||||
// FileMetadata represents decrypted file metadata (populated after decryption)
|
||||
type FileMetadata struct {
|
||||
Name string `json:"name"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Size int64 `json:"size"`
|
||||
FileExtension string `json:"file_extension"`
|
||||
}
|
||||
|
||||
// IsCloudOnly returns true if the file only exists in the cloud
|
||||
func (f *File) IsCloudOnly() bool {
|
||||
return f.SyncStatus == SyncStatusCloudOnly
|
||||
}
|
||||
|
||||
// IsSynced returns true if the file is synchronized between local and cloud
|
||||
func (f *File) IsSynced() bool {
|
||||
return f.SyncStatus == SyncStatusSynced
|
||||
}
|
||||
|
||||
// IsLocalOnly returns true if the file only exists locally
|
||||
func (f *File) IsLocalOnly() bool {
|
||||
return f.SyncStatus == SyncStatusLocalOnly
|
||||
}
|
||||
|
||||
// HasLocalContent returns true if the file has local content (not just metadata)
|
||||
func (f *File) HasLocalContent() bool {
|
||||
return f.FilePath != "" || f.EncryptedFilePath != ""
|
||||
}
|
||||
|
||||
// IsDeleted returns true if the file is marked as deleted
|
||||
func (f *File) IsDeleted() bool {
|
||||
return f.State == StateDeleted
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue