Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions krillnotes-desktop/src-tauri/src/commands/attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,37 @@ pub async fn open_attachment(
.open_path(tmp_path.to_string_lossy().as_ref(), None::<&str>)
.map_err(|e: tauri_plugin_opener::Error| e.to_string())
}

const DEFAULT_ATTACHMENT_MAX_SIZE_MB: u64 = 10;

#[tauri::command]
pub async fn get_attachment_max_size_mb(
window: tauri::Window,
state: tauri::State<'_, crate::AppState>,
) -> Result<u64, String> {
let workspaces = state.workspaces.lock().map_err(|e| e.to_string())?;
let ws = workspaces
.get(window.label())
.ok_or_else(|| "No workspace open".to_string())?;
let bytes = ws.attachment_max_size_bytes().map_err(|e| e.to_string())?;
Ok(bytes
.map(|b| b / (1024 * 1024))
.unwrap_or(DEFAULT_ATTACHMENT_MAX_SIZE_MB))
}

#[tauri::command]
pub async fn set_attachment_max_size_mb(
window: tauri::Window,
state: tauri::State<'_, crate::AppState>,
limit_mb: u64,
) -> Result<(), String> {
if !(1..=500).contains(&limit_mb) {
return Err("Attachment size limit must be between 1 and 500 MB".to_string());
}
let mut workspaces = state.workspaces.lock().map_err(|e| e.to_string())?;
let ws = workspaces
.get_mut(window.label())
.ok_or_else(|| "No workspace open".to_string())?;
ws.set_attachment_max_size_bytes(Some(limit_mb * 1024 * 1024))
.map_err(|e| e.to_string())
}
2 changes: 2 additions & 0 deletions krillnotes-desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ pub fn run() {
delete_attachment,
restore_attachment,
open_attachment,
get_attachment_max_size_mb,
set_attachment_max_size_mb,
undo,
redo,
can_undo,
Expand Down
49 changes: 48 additions & 1 deletion krillnotes-desktop/src/components/WorkspacePropertiesDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ function WorkspacePropertiesDialog({ isOpen, onClose }: WorkspacePropertiesDialo
const [error, setError] = useState('');
const [saving, setSaving] = useState(false);
const [isOwner, setIsOwner] = useState(true);
const [attachmentSizeMb, setAttachmentSizeMb] = useState<number>(10);

useEffect(() => {
if (!isOpen) return;
invoke<boolean>('is_workspace_owner').then(setIsOwner).catch(() => setIsOwner(false));
invoke<number>('get_attachment_max_size_mb').then(setAttachmentSizeMb).catch(() => {});
invoke<WorkspaceMetadata>('get_workspace_metadata')
.then(meta => {
setAuthorName(meta.authorName ?? '');
Expand Down Expand Up @@ -120,6 +122,7 @@ function WorkspacePropertiesDialog({ isOpen, onClose }: WorkspacePropertiesDialo
tags: parseTags(tagsRaw),
};
await invoke('set_workspace_metadata', { metadata });
await invoke('set_attachment_max_size_mb', { limitMb: attachmentSizeMb });
onClose();
} catch (err) {
setError(t('workspace.propertiesSaveFailed', { error: String(err) }));
Expand Down Expand Up @@ -151,6 +154,50 @@ function WorkspacePropertiesDialog({ isOpen, onClose }: WorkspacePropertiesDialo
</div>
)}

<h3 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide mb-3">
{t('workspace.settingsSection')}
</h3>

<div className="mb-3">
<label className="block text-sm font-medium mb-1">
{t('workspace.attachmentSizeLimit')}
</label>
<div className="flex items-center gap-2">
<input
type="number"
inputMode="numeric"
min={1}
max={500}
step={1}
value={attachmentSizeMb}
onChange={e => {
const v = parseInt(e.target.value, 10);
if (!isNaN(v)) setAttachmentSizeMb(v);
}}
className={`w-24 bg-secondary border border-secondary rounded px-3 py-1.5 text-sm ${!isOwner ? 'opacity-60 cursor-default' : ''}`}
readOnly={!isOwner}
disabled={!isOwner}
/>
<span className="text-sm text-muted-foreground">
{t('workspace.attachmentSizeLimitUnit')}
</span>
</div>
<p className="text-xs text-muted-foreground mt-1">
{t('workspace.attachmentSizeLimitHelper')}
</p>
{(attachmentSizeMb < 1 || attachmentSizeMb > 500) && (
<p className="text-xs text-red-500 mt-1">
{t('workspace.attachmentSizeLimitError')}
</p>
)}
</div>

<hr className="border-secondary my-4" />

<h3 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide mb-3">
{t('workspace.propertiesSection')}
</h3>

{field(t('workspace.authorName'), (
<input type="text" value={authorName} onChange={e => setAuthorName(e.target.value)}
className={inputClass} placeholder={t('workspace.authorNamePlaceholder')}
Expand Down Expand Up @@ -247,7 +294,7 @@ function WorkspacePropertiesDialog({ isOpen, onClose }: WorkspacePropertiesDialo
</button>
<button onClick={handleSave}
className="px-4 py-2 bg-primary text-primary-foreground rounded hover:bg-primary/90"
disabled={saving}>
disabled={saving || attachmentSizeMb < 1 || attachmentSizeMb > 500}>
{saving ? t('common.saving') : t('common.save')}
</button>
</>
Expand Down
8 changes: 7 additions & 1 deletion krillnotes-desktop/src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@
"redoTooltip": "Wiederholen (Cmd+Umschalt+Z)",
"schemaMigrated_one": "Schema \"{{schemaName}}\" aktualisiert — {{count}} Notiz auf Version {{version}} migriert",
"schemaMigrated_other": "Schema \"{{schemaName}}\" aktualisiert — {{count}} Notizen auf Version {{version}} migriert",
"propertiesReadOnly": "Nur der Eigentümer des Arbeitsbereichs kann diese Eigenschaften ändern."
"propertiesReadOnly": "Nur der Eigentümer des Arbeitsbereichs kann diese Eigenschaften ändern.",
"settingsSection": "Einstellungen",
"propertiesSection": "Eigenschaften",
"attachmentSizeLimit": "Maximale Anhangsgröße",
"attachmentSizeLimitHelper": "Maximale Dateigröße für Anhänge in diesem Arbeitsbereich",
"attachmentSizeLimitUnit": "MB",
"attachmentSizeLimitError": "Muss zwischen 1 und 500 MB liegen"
},
"dialogs": {
"password": {
Expand Down
8 changes: 7 additions & 1 deletion krillnotes-desktop/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@
"redoTooltip": "Redo (Cmd+Shift+Z)",
"schemaMigrated_one": "\"{{schemaName}}\" schema updated — {{count}} note migrated to version {{version}}",
"schemaMigrated_other": "\"{{schemaName}}\" schema updated — {{count}} notes migrated to version {{version}}",
"propertiesReadOnly": "Only the workspace owner can modify these properties."
"propertiesReadOnly": "Only the workspace owner can modify these properties.",
"settingsSection": "Settings",
"propertiesSection": "Properties",
"attachmentSizeLimit": "Maximum attachment size",
"attachmentSizeLimitHelper": "Maximum file size for attachments in this workspace",
"attachmentSizeLimitUnit": "MB",
"attachmentSizeLimitError": "Must be between 1 and 500 MB"
},
"dialogs": {
"password": {
Expand Down
8 changes: 7 additions & 1 deletion krillnotes-desktop/src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@
"redoTooltip": "Rehacer (Cmd+Mayús+Z)",
"schemaMigrated_one": "Esquema \"{{schemaName}}\" actualizado — {{count}} nota migrada a versión {{version}}",
"schemaMigrated_other": "Esquema \"{{schemaName}}\" actualizado — {{count}} notas migradas a versión {{version}}",
"propertiesReadOnly": "Solo el propietario del espacio de trabajo puede modificar estas propiedades."
"propertiesReadOnly": "Solo el propietario del espacio de trabajo puede modificar estas propiedades.",
"settingsSection": "Configuración",
"propertiesSection": "Propiedades",
"attachmentSizeLimit": "Tamaño máximo de adjuntos",
"attachmentSizeLimitHelper": "Tamaño máximo de archivo para adjuntos en este espacio de trabajo",
"attachmentSizeLimitUnit": "MB",
"attachmentSizeLimitError": "Debe estar entre 1 y 500 MB"
},
"dialogs": {
"password": {
Expand Down
8 changes: 7 additions & 1 deletion krillnotes-desktop/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@
"redoTooltip": "Rétablir (Cmd+Maj+Z)",
"schemaMigrated_one": "Schéma \"{{schemaName}}\" mis à jour — {{count}} note migrée vers la version {{version}}",
"schemaMigrated_other": "Schéma \"{{schemaName}}\" mis à jour — {{count}} notes migrées vers la version {{version}}",
"propertiesReadOnly": "Seul le propriétaire de l'espace de travail peut modifier ces propriétés."
"propertiesReadOnly": "Seul le propriétaire de l'espace de travail peut modifier ces propriétés.",
"settingsSection": "Paramètres",
"propertiesSection": "Propriétés",
"attachmentSizeLimit": "Taille maximale des pièces jointes",
"attachmentSizeLimitHelper": "Taille maximale des fichiers joints dans cet espace de travail",
"attachmentSizeLimitUnit": "Mo",
"attachmentSizeLimitError": "Doit être compris entre 1 et 500 Mo"
},
"dialogs": {
"password": {
Expand Down
8 changes: 7 additions & 1 deletion krillnotes-desktop/src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@
"redoTooltip": "やり直す (Cmd+Shift+Z)",
"schemaMigrated_one": "スキーマ「{{schemaName}}」更新 — {{count}}件のノートをバージョン{{version}}に移行しました",
"schemaMigrated_other": "スキーマ「{{schemaName}}」更新 — {{count}}件のノートをバージョン{{version}}に移行しました",
"propertiesReadOnly": "ワークスペースのプロパティを変更できるのはオーナーのみです。"
"propertiesReadOnly": "ワークスペースのプロパティを変更できるのはオーナーのみです。",
"settingsSection": "設定",
"propertiesSection": "プロパティ",
"attachmentSizeLimit": "添付ファイルの最大サイズ",
"attachmentSizeLimitHelper": "このワークスペースの添付ファイルの最大サイズ",
"attachmentSizeLimitUnit": "MB",
"attachmentSizeLimitError": "1〜500 MBの範囲で指定してください"
},
"dialogs": {
"password": {
Expand Down
8 changes: 7 additions & 1 deletion krillnotes-desktop/src/i18n/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@
"redoTooltip": "다시 실행 (Cmd+Shift+Z)",
"schemaMigrated_one": "스키마 \"{{schemaName}}\" 업데이트 — {{count}}개의 노트가 버전 {{version}}으로 마이그레이션됨",
"schemaMigrated_other": "스키마 \"{{schemaName}}\" 업데이트 — {{count}}개의 노트가 버전 {{version}}으로 마이그레이션됨",
"propertiesReadOnly": "워크스페이스 소유자만 이 속성을 수정할 수 있습니다."
"propertiesReadOnly": "워크스페이스 소유자만 이 속성을 수정할 수 있습니다.",
"settingsSection": "설정",
"propertiesSection": "속성",
"attachmentSizeLimit": "최대 첨부 파일 크기",
"attachmentSizeLimitHelper": "이 워크스페이스의 첨부 파일 최대 크기",
"attachmentSizeLimitUnit": "MB",
"attachmentSizeLimitError": "1~500 MB 사이여야 합니다"
},
"dialogs": {
"password": {
Expand Down
8 changes: 7 additions & 1 deletion krillnotes-desktop/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@
"redoTooltip": "重做 (Cmd+Shift+Z)",
"schemaMigrated_one": "模式 \"{{schemaName}}\" 已更新 — {{count}} 个笔记已迁移到版本 {{version}}",
"schemaMigrated_other": "模式 \"{{schemaName}}\" 已更新 — {{count}} 个笔记已迁移到版本 {{version}}",
"propertiesReadOnly": "只有工作区所有者才能修改这些属性。"
"propertiesReadOnly": "只有工作区所有者才能修改这些属性。",
"settingsSection": "设置",
"propertiesSection": "属性",
"attachmentSizeLimit": "附件最大大小",
"attachmentSizeLimitHelper": "此工作区附件的最大文件大小",
"attachmentSizeLimitUnit": "MB",
"attachmentSizeLimitError": "必须在 1 到 500 MB 之间"
},
"dialogs": {
"password": {
Expand Down
Loading