Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add attachment download option to credential view screen (#1010)
Leendert de Borsta674baa6d612
diff --git a/apps/mobile-app/app/(tabs)/credentials/[id].tsx b/apps/mobile-app/app/(tabs)/credentials/[id].tsxindex ae11b94f2..43fe69936 100644--- a/apps/mobile-app/app/(tabs)/credentials/[id].tsx+++ b/apps/mobile-app/app/(tabs)/credentials/[id].tsx@@ -11,6 +11,7 @@ import { useColors } from '@/hooks/useColorScheme';import { CredentialIcon } from '@/components/credentials/CredentialIcon';import { AliasDetails } from '@/components/credentials/details/AliasDetails';+import { AttachmentSection } from '@/components/credentials/details/AttachmentSection';import { EmailPreview } from '@/components/credentials/details/EmailPreview';import { LoginCredentials } from '@/components/credentials/details/LoginCredentials';import { NotesSection } from '@/components/credentials/details/NotesSection';@@ -135,6 +136,7 @@ export default function CredentialDetailsScreen() : React.ReactNode {<LoginCredentials credential={credential} /><AliasDetails credential={credential} /><NotesSection credential={credential} />+ <AttachmentSection credential={credential} /></ThemedScrollView></ThemedContainer>);diff --git a/apps/mobile-app/components/credentials/details/AttachmentSection.tsx b/apps/mobile-app/components/credentials/details/AttachmentSection.tsxnew file mode 100644index 000000000..c57bfd8ff--- /dev/null+++ b/apps/mobile-app/components/credentials/details/AttachmentSection.tsx@@ -0,0 +1,153 @@+import * as Sharing from 'expo-sharing';+import React, { useState, useEffect } from 'react';+import { useTranslation } from 'react-i18next';+import { View, StyleSheet, TouchableOpacity, Platform, Alert } from 'react-native';+import * as FileSystem from 'expo-file-system';++import type { Credential, Attachment } from '@/utils/dist/shared/models/vault';++import { useColors } from '@/hooks/useColorScheme';++import { ThemedText } from '@/components/themed/ThemedText';+import { ThemedView } from '@/components/themed/ThemedView';+import { useDb } from '@/context/DbContext';++type AttachmentSectionProps = {+ credential: Credential;+};++/**+ * Attachment section component.+ */+export const AttachmentSection: React.FC<AttachmentSectionProps> = ({ credential }): React.ReactNode => {+ const [attachments, setAttachments] = useState<Attachment[]>([]);+ const colors = useColors();+ const dbContext = useDb();+ const { t } = useTranslation();++ /**+ * Download and share an attachment.+ */+ const downloadAttachment = async (attachment: Attachment): Promise<void> => {+ try {+ // Convert Uint8Array or number[] to Uint8Array+ const byteArray = attachment.Blob instanceof Uint8Array+ ? attachment.Blob+ : new Uint8Array(attachment.Blob);++ const fileUri = `${FileSystem.documentDirectory}${attachment.Filename}`;++ // Convert byte array to base64+ let binary = '';+ const bytes = new Uint8Array(byteArray);+ const len = bytes.byteLength;+ for (let i = 0; i < len; i++) {+ binary += String.fromCharCode(bytes[i]);+ }+ const base64 = btoa(binary);++ // Write file to local storage+ await FileSystem.writeAsStringAsync(fileUri, base64, {+ encoding: FileSystem.EncodingType.Base64,+ });++ // Share the file+ if (await Sharing.isAvailableAsync()) {+ await Sharing.shareAsync(fileUri, {+ mimeType: 'application/octet-stream',+ dialogTitle: attachment.Filename,+ });+ } else {+ Alert.alert('Download Complete', `File saved to: ${fileUri}`);+ }+ } catch (error) {+ console.error('Error downloading attachment:', error);+ Alert.alert('Error', 'Failed to download attachment');+ }+ };++ useEffect(() => {+ /**+ * Load the attachments.+ */+ const loadAttachments = async (): Promise<void> => {+ if (!dbContext?.sqliteClient) {+ return;+ }++ try {+ const attachmentList = await dbContext.sqliteClient.getAttachmentsForCredential(credential.Id);+ setAttachments(attachmentList);+ } catch (error) {+ console.error('Error loading attachments:', error);+ }+ };++ loadAttachments();+ }, [credential.Id, dbContext?.sqliteClient]);++ if (attachments.length === 0) {+ return null;+ }++ const styles = StyleSheet.create({+ container: {+ paddingTop: 16,+ },+ content: {+ backgroundColor: colors.accentBackground,+ borderRadius: 8,+ marginTop: 8,+ padding: 12,+ },+ attachmentItem: {+ alignItems: 'center',+ flexDirection: 'row',+ justifyContent: 'space-between',+ marginBottom: 8,+ },+ attachmentInfo: {+ flex: 1,+ },+ attachmentName: {+ fontSize: 14,+ fontWeight: '500',+ marginBottom: 2,+ },+ attachmentDate: {+ fontSize: 12,+ },+ downloadIcon: {+ marginLeft: 12,+ },+ });++ return (+ <ThemedView style={styles.container}>+ <ThemedText type="subtitle">+ {t('credentials.attachments')}+ </ThemedText>+ {attachments.map(attachment => (+ <TouchableOpacity+ key={attachment.Id}+ style={styles.content}+ onPress={() => downloadAttachment(attachment)}+ >+ <View style={styles.attachmentItem}>+ <View style={styles.attachmentInfo}>+ <ThemedText style={styles.attachmentName}>+ {attachment.Filename}+ </ThemedText>+ <ThemedText style={styles.attachmentDate} type="subtitle">+ {new Date(attachment.CreatedAt).toLocaleDateString()}+ </ThemedText>+ </View>+ <View style={styles.downloadIcon}>+ <ThemedText type="subtitle">📎</ThemedText>+ </View>+ </View>+ </TouchableOpacity>+ ))}+ </ThemedView>+ );+};\ No newline at end of filediff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.jsonindex d640f5f1e..f8bab724a 100644--- a/apps/mobile-app/i18n/locales/en.json+++ b/apps/mobile-app/i18n/locales/en.json@@ -97,6 +97,10 @@"switchBackToBrowser": "Switch back to your browser to continue.","twoFactorAuth": "Two-factor authentication","totpCode": "TOTP Code",+ "attachments": "Attachments",+ "loadingAttachments": "Loading attachments...",+ "addAttachments": "Add Attachments",+ "deleteAttachment": "Delete","errors": {"loadFailed": "Failed to load credential","generateUsernameFailed": "Failed to generate username",diff --git a/apps/mobile-app/ios/Podfile.lock b/apps/mobile-app/ios/Podfile.lockindex 028c0733cd..893805a7b 100644--- a/apps/mobile-app/ios/Podfile.lock+++ b/apps/mobile-app/ios/Podfile.lock@@ -222,6 +222,8 @@ PODS:- ExpoModulesCore- ExpoClipboard (7.0.1):- ExpoModulesCore+ - ExpoDocumentPicker (13.1.6):+ - ExpoModulesCore- ExpoFileSystem (18.0.12):- ExpoModulesCore- ExpoFont (13.0.4):@@ -2195,6 +2197,7 @@ DEPENDENCIES:- ExpoAsset (from `../node_modules/expo-asset/ios`)- ExpoBlur (from `../node_modules/expo-blur/ios`)- ExpoClipboard (from `../node_modules/expo-clipboard/ios`)+ - ExpoDocumentPicker (from `../node_modules/expo-document-picker/ios`)- ExpoFileSystem (from `../node_modules/expo-file-system/ios`)- ExpoFont (from `../node_modules/expo-font/ios`)- ExpoHaptics (from `../node_modules/expo-haptics/ios`)@@ -2329,6 +2332,8 @@ EXTERNAL SOURCES::path: "../node_modules/expo-blur/ios"ExpoClipboard::path: "../node_modules/expo-clipboard/ios"+ ExpoDocumentPicker:+ :path: "../node_modules/expo-document-picker/ios"ExpoFileSystem::path: "../node_modules/expo-file-system/ios"ExpoFont:@@ -2528,6 +2533,7 @@ SPEC CHECKSUMS:ExpoAsset: 48386d40d53a8c1738929b3ed509bcad595b5516ExpoBlur: 392c1207f71d0ecf22371621c1fbd44ba84d9742ExpoClipboard: 44fd1c8959ee8f6175d059dc011b154c9709a969+ ExpoDocumentPicker: b263a279685b6640b8c8bc70d71c83067aeaae55ExpoFileSystem: 42d363d3b96f9afab980dcef60d5657a4443c655ExpoFont: f354e926f8feae5e831ec8087f36652b44a0b188ExpoHaptics: 8d199b2f33245ea85289ff6c954c7ee7c00a5b5ddiff --git a/apps/mobile-app/package-lock.json b/apps/mobile-app/package-lock.jsonindex 7b3ed9936..113834976 100644--- a/apps/mobile-app/package-lock.json+++ b/apps/mobile-app/package-lock.json@@ -19,6 +19,8 @@"expo-clipboard": "~7.0.1","expo-constants": "~17.0.8","expo-dev-client": "~5.0.19",+ "expo-document-picker": "^13.1.6",+ "expo-file-system": "~18.0.12","expo-font": "~13.0.4","expo-haptics": "~14.0.1","expo-linear-gradient": "~14.0.2",@@ -61,7 +63,7 @@},"devDependencies": {"@babel/core": "^7.25.2",- "@react-native-community/cli": "*",+ "@react-native-community/cli": "latest","@types/argon2-browser": "^1.18.4","@types/fbemitter": "^2.0.35","@types/jest": "^29.5.12",@@ -11147,6 +11149,15 @@"expo": "*"}},+ "node_modules/expo-document-picker": {+ "version": "13.1.6",+ "resolved": "https://registry.npmjs.org/expo-document-picker/-/expo-document-picker-13.1.6.tgz",+ "integrity": "sha512-8FTQPDOkyCvFN/i4xyqzH7ELW4AsB6B3XBZQjn1FEdqpozo6rpNJRr7sWFU/93WrLgA9FJEKpKbyr6XxczK6BA==",+ "license": "MIT",+ "peerDependencies": {+ "expo": "*"+ }+ },"node_modules/expo-file-system": {"version": "18.0.12","resolved": "https://registry.npmjs.org/expo-file-system/-/expo-file-system-18.0.12.tgz",diff --git a/apps/mobile-app/package.json b/apps/mobile-app/package.jsonindex d51fa96e6..015fb6291 100644--- a/apps/mobile-app/package.json+++ b/apps/mobile-app/package.json@@ -40,6 +40,8 @@"expo-clipboard": "~7.0.1","expo-constants": "~17.0.8","expo-dev-client": "~5.0.19",+ "expo-document-picker": "^13.1.6",+ "expo-file-system": "~18.0.12","expo-font": "~13.0.4","expo-haptics": "~14.0.1","expo-linear-gradient": "~14.0.2",diff --git a/apps/mobile-app/utils/SqliteClient.tsx b/apps/mobile-app/utils/SqliteClient.tsxindex 5660b581b..a0203caee 100644--- a/apps/mobile-app/utils/SqliteClient.tsx+++ b/apps/mobile-app/utils/SqliteClient.tsx@@ -686,6 +686,35 @@ class SqliteClient {}}+ /**+ * Get attachments for a specific credential+ * @param credentialId - The ID of the credential+ * @returns Array of attachments for the credential+ */+ public async getAttachmentsForCredential(credentialId: string): Promise<Attachment[]> {+ try {+ if (!await this.tableExists('Attachments')) {+ return [];+ }++ const query = `+ SELECT+ Id,+ Filename,+ Blob,+ CredentialId,+ CreatedAt,+ UpdatedAt,+ IsDeleted+ FROM Attachments+ WHERE CredentialId = ? AND IsDeleted = 0`;+ return this.executeQuery<Attachment>(query, [credentialId]);+ } catch (error) {+ console.error('Error getting attachments:', error);+ return [];+ }+ }+/*** Check if a table exists in the database* @param tableName - The name of the table to checkdiff --git a/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts b/apps/mobile-app/utils/dist/shared/models/vault/index.d.tsindex 5693b65b4..2cb31d3ef 100644--- a/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts+++ b/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts@@ -77,4 +77,17 @@ type Alias = {Email?: string;};-export type { Alias, Credential, EncryptionKey, PasswordSettings, TotpCode };+/**+ * Attachment SQLite database type.+ */+type Attachment = {+ Id: string;+ Filename: string;+ Blob: Uint8Array | number[];+ CredentialId: string;+ CreatedAt: string;+ UpdatedAt: string;+ IsDeleted?: boolean;+};++export type { Alias, Attachment, Credential, EncryptionKey, PasswordSettings, TotpCode };