Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

Add mobile resource uploads

yoma1bb1cf118de7
diff --git a/apps/mobile/package.json b/apps/mobile/package.json
index 81efb4ef..984bda82 100644
--- a/apps/mobile/package.json
+++ b/apps/mobile/package.json
@@ -17,6 +17,7 @@
"@gorhom/bottom-sheet": "latest",
"@tanstack/react-query": "latest",
"expo": "latest",
+ "expo-document-picker": "~57.0.0",
"expo-router": "latest",
"expo-secure-store": "latest",
"expo-status-bar": "latest",
@@ -33,6 +34,6 @@
"@types/react": "latest",
"babel-preset-expo": "latest",
"gluestack-ui": "latest",
- "typescript": "latest"
+ "typescript": "6.0.3"
}
}
diff --git a/apps/mobile/src/screens/WorkspaceScreen.tsx b/apps/mobile/src/screens/WorkspaceScreen.tsx
index 05af3b79..b949f8a5 100644
--- a/apps/mobile/src/screens/WorkspaceScreen.tsx
+++ b/apps/mobile/src/screens/WorkspaceScreen.tsx
@@ -1,5 +1,6 @@
import { useEffect, useState, type ReactNode } from "react";
import { useMutation, useQuery, useQueryClient, type UseMutationResult } from "@tanstack/react-query";
+import * as DocumentPicker from "expo-document-picker";
import type { MemoFilterMode, MemoSortMode } from "@edgeever/client";
import {
Archive,
@@ -23,6 +24,7 @@ import {
Settings,
Tag,
Trash2,
+ Upload,
UserRound,
X,
} from "lucide-react-native";
@@ -1405,6 +1407,7 @@ const ResourcesModal = ({
visible: boolean;
}) => {
const { client } = useSession();
+ const queryClient = useQueryClient();
const [searchText, setSearchText] = useState("");
const [filter, setFilter] = useState<ResourceFilter>("all");
const [previewResource, setPreviewResource] = useState<ResourceListItem | null>(null);
@@ -1421,6 +1424,56 @@ const ResourcesModal = ({
enabled: Boolean(client && visible),
});
+ const uploadResourceMutation = useMutation({
+ mutationFn: async () => {
+ if (!client || !activeMemo) {
+ throw new Error("请先打开一条可用笔记");
+ }
+
+ if (activeMemo.isDeleted) {
+ throw new Error("回收站中的笔记不能上传资源");
+ }
+
+ const result = await DocumentPicker.getDocumentAsync({
+ copyToCacheDirectory: true,
+ multiple: false,
+ type: "*/*",
+ });
+
+ if (result.canceled) {
+ return null;
+ }
+
+ const asset = result.assets[0];
+
+ if (!asset?.uri) {
+ throw new Error("没有选择文件");
+ }
+
+ const form = new FormData();
+ form.append("file", {
+ uri: asset.uri,
+ name: asset.name || "upload",
+ type: asset.mimeType || "application/octet-stream",
+ } as unknown as Blob);
+
+ const response = await client.uploadMemoResource(activeMemo.id, form);
+ return response.resource;
+ },
+ onSuccess: async (resource) => {
+ if (!resource) {
+ return;
+ }
+
+ await Promise.all([
+ queryClient.invalidateQueries({ queryKey: ["mobile", "resources"] }),
+ queryClient.invalidateQueries({ queryKey: ["mobile", "memo"] }),
+ queryClient.invalidateQueries({ queryKey: ["mobile", "memos"] }),
+ ]);
+ setFilter(resource.kind === "image" ? "image" : "all");
+ },
+ });
+
const resources = resourcesQuery.data?.resources ?? [];
const summary = resourcesQuery.data?.summary ?? {
totalCount: 0,
@@ -1507,9 +1560,21 @@ const ResourcesModal = ({
<OptionPill active={filter === "other"} label="其他" onPress={() => setFilter("other")} />
</ScrollView>
+ <Pressable
+ disabled={!activeMemo || activeMemo.isDeleted || uploadResourceMutation.isPending}
+ onPress={() => uploadResourceMutation.mutate()}
+ style={[styles.uploadButton, (!activeMemo || activeMemo.isDeleted || uploadResourceMutation.isPending) && styles.buttonDisabled]}
+ >
+ {uploadResourceMutation.isPending ? <ActivityIndicator color="#ffffff" /> : <Upload color="#ffffff" size={18} />}
+ <Text style={styles.uploadButtonText}>{uploadResourceMutation.isPending ? "上传中" : "上传附件"}</Text>
+ </Pressable>
+
<Text style={styles.assetsHint}>
{activeMemo ? `当前笔记:${activeMemo.title?.trim() || activeMemo.excerpt || DEFAULT_MEMO_TITLE}` : "打开一条笔记后可作为资源上传目标"}
</Text>
+ {uploadResourceMutation.error ? (
+ <Text style={styles.errorText}>{uploadResourceMutation.error instanceof Error ? uploadResourceMutation.error.message : "上传失败"}</Text>
+ ) : null}
</View>
{resourcesQuery.isLoading ? (
@@ -2468,6 +2533,21 @@ const styles = StyleSheet.create({
fontWeight: "700",
lineHeight: 18,
},
+ uploadButton: {
+ alignItems: "center",
+ backgroundColor: "#047857",
+ borderRadius: 8,
+ flexDirection: "row",
+ gap: 8,
+ justifyContent: "center",
+ minHeight: 44,
+ paddingHorizontal: 14,
+ },
+ uploadButtonText: {
+ color: "#ffffff",
+ fontSize: 14,
+ fontWeight: "800",
+ },
sectionTitle: {
color: "#0f172a",
fontSize: 21,
diff --git a/bun.lock b/bun.lock
index 9abc24f6..12327d8f 100644
--- a/bun.lock
+++ b/bun.lock
@@ -76,6 +76,7 @@
"@gorhom/bottom-sheet": "latest",
"@tanstack/react-query": "latest",
"expo": "latest",
+ "expo-document-picker": "~57.0.0",
"expo-router": "latest",
"expo-secure-store": "latest",
"expo-status-bar": "latest",
@@ -92,7 +93,7 @@
"@types/react": "latest",
"babel-preset-expo": "latest",
"gluestack-ui": "latest",
- "typescript": "latest",
+ "typescript": "6.0.3",
},
},
"apps/site": {
@@ -1537,6 +1538,8 @@
"expo-constants": ["[email protected]", "", { "dependencies": { "@expo/env": "~2.4.1" }, "peerDependencies": { "expo": "*", "react-native": "*" } }, "sha512-BghbZlzwFnA22BG0CWv6W29zx8w19FozYPfSeZ3HjMitoy4aAmF1FnFbbjYSmZz6HHXXTWOfqwobOEIaglfzxg=="],
+ "expo-document-picker": ["[email protected]", "", { "peerDependencies": { "expo": "*" } }, "sha512-foT1pA3tD7KvcqXwjQBh4qEDjHT9U9MhZ6H2aF38VolCiHRhXDQLtKQqCeXjbHxJhSf8HC/YPV3IRxDxFTL2sA=="],
+
"expo-file-system": ["[email protected]", "", { "peerDependencies": { "expo": "*", "react-native": "*" } }, "sha512-G+eytNuNGMiS7dbdj1j0nAYMowXnNr1vpO+jss6nQvBlRxshcGBFMtk8xfc67ynz0MUVkzod7WwKO7Vf1iOaJw=="],
"expo-font": ["[email protected]", "", { "dependencies": { "fontfaceobserver": "^2.1.0" }, "peerDependencies": { "expo": "*", "react": "*", "react-native": "*" } }, "sha512-zF+J7WrNFjqyAADwdvDgkFEoIQv9DqcjJ57HVstNEH7/7Tx1ThPEhKraodEQOwSjMYWirP+4BYsVbdb+/Zr4QQ=="],