修复 筛选不生效的问题
This commit is contained in:
1 parent
9b258e4abd
commit
9e26770e96
16 files changed
+159
-125
No files matched your search
+1
-1
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## [0.1.0] - 2024-11-XX
|
## [1.0.0] - 2024-11-XX
|
||||||
|
|
||||||
### 初始版本
|
### 初始版本
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flypic-backend",
|
"name": "flypic-backend",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"description": "FlyPic backend server",
|
"description": "FlyPic backend server",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
BIN
Binary file not shown.
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "flypic-backend",
|
"name": "flypic-backend",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "flypic-backend",
|
"name": "flypic-backend",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^9.2.2",
|
"better-sqlite3": "^9.2.2",
|
||||||
"chokidar": "^3.6.0",
|
"chokidar": "^3.6.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flypic-backend",
|
"name": "flypic-backend",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"description": "FlyPic backend server",
|
"description": "FlyPic backend server",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class LibraryService {
|
|||||||
} catch (writeError) {
|
} catch (writeError) {
|
||||||
console.log(`[LibraryService] No write permission: ${normalizedPath}`);
|
console.log(`[LibraryService] No write permission: ${normalizedPath}`);
|
||||||
throw new ValidationError(
|
throw new ValidationError(
|
||||||
'无法访问该文件夹。请在飞牛 fnOS 的"数据共享"中将此文件夹添加到 FlyPic 应用的访问权限。',
|
'无法访问该文件夹。将此文件夹添加到 FlyPic 应用的访问权限。',
|
||||||
'permission'
|
'permission'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ class LibraryService {
|
|||||||
if (readError.code === 'EACCES' || readError.code === 'EPERM') {
|
if (readError.code === 'EACCES' || readError.code === 'EPERM') {
|
||||||
console.log(`[LibraryService] No access permission: ${normalizedPath}`);
|
console.log(`[LibraryService] No access permission: ${normalizedPath}`);
|
||||||
throw new ValidationError(
|
throw new ValidationError(
|
||||||
'无法访问该文件夹。请在飞牛 fnOS 的"数据共享"中将此文件夹添加到 FlyPic 应用的访问权限。',
|
'无法访问该文件夹。将此文件夹添加到 FlyPic 应用的访问权限。',
|
||||||
'permission'
|
'permission'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
appname=flypic
|
appname=flypic
|
||||||
version=0.1.0
|
version=1.0.0
|
||||||
desc=飞图 - 专为飞牛 fnOS 设计的轻量、快速、稳定的图像素材检索浏览应用,支持数十万级别图片流畅浏览,非侵入式设计,100% 开源免费
|
desc=飞图 - 专为飞牛 fnOS 设计的轻量、快速、稳定的图像素材检索浏览应用,支持数十万级别图片流畅浏览,非侵入式设计,100% 开源免费
|
||||||
arch=x86_64
|
arch=x86_64
|
||||||
display_name=FlyPic
|
display_name=FlyPic
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flypic-frontend",
|
"name": "flypic-frontend",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -8,19 +8,21 @@ import { libraryAPI, scanAPI, watchAPI } from '../api';
|
|||||||
|
|
||||||
function Header() {
|
function Header() {
|
||||||
const { currentLibraryId } = useLibraryStore();
|
const { currentLibraryId } = useLibraryStore();
|
||||||
const { searchKeywords, images, selectedFolder, setSearchKeywords } = useImageStore();
|
const { searchKeywords, originalImages, selectedFolder, setSearchKeywords, filters, setFilters, resetFilters } = useImageStore();
|
||||||
const { theme, toggleTheme, thumbnailHeight, setThumbnailHeight, mobileView } = useUIStore();
|
const { theme, toggleTheme, thumbnailHeight, setThumbnailHeight, mobileView } = useUIStore();
|
||||||
|
|
||||||
const [showFilters, setShowFilters] = useState(false);
|
const [showFilters, setShowFilters] = useState(false);
|
||||||
const [selectedFormats, setSelectedFormats] = useState([]);
|
|
||||||
const [selectedSizes, setSelectedSizes] = useState([]);
|
|
||||||
const [selectedOrientation, setSelectedOrientation] = useState('');
|
|
||||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||||
const [isMobile, setIsMobile] = useState(false);
|
const [isMobile, setIsMobile] = useState(false);
|
||||||
const [showMobileSettings, setShowMobileSettings] = useState(false);
|
const [showMobileSettings, setShowMobileSettings] = useState(false);
|
||||||
const [localSearchValue, setLocalSearchValue] = useState(searchKeywords);
|
const [localSearchValue, setLocalSearchValue] = useState(searchKeywords);
|
||||||
const searchDebounceRef = useRef(null);
|
const searchDebounceRef = useRef(null);
|
||||||
|
|
||||||
|
// 从全局 store 获取筛选状态
|
||||||
|
const selectedFormats = filters.formats || [];
|
||||||
|
const selectedSizes = filters.sizes || [];
|
||||||
|
const selectedOrientation = filters.orientation || '';
|
||||||
|
|
||||||
// 检测移动端
|
// 检测移动端
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkMobile = () => {
|
const checkMobile = () => {
|
||||||
@@ -33,10 +35,8 @@ function Header() {
|
|||||||
|
|
||||||
// 监听文件夹变化,自动清空筛选
|
// 监听文件夹变化,自动清空筛选
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedFormats([]);
|
resetFilters();
|
||||||
setSelectedSizes([]);
|
}, [selectedFolder, resetFilters]);
|
||||||
setSelectedOrientation('');
|
|
||||||
}, [selectedFolder]);
|
|
||||||
|
|
||||||
// 🎯 内存优化:禁用前端启动 chokidar 文件监控
|
// 🎯 内存优化:禁用前端启动 chokidar 文件监控
|
||||||
// 后端已经使用轻量级监控器(智能轮询),不需要前端启动
|
// 后端已经使用轻量级监控器(智能轮询),不需要前端启动
|
||||||
@@ -167,9 +167,9 @@ function Header() {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 分析当前文件夹的所有图片,生成可选项(只在images变化时计算一次)
|
// 分析原始图片列表,生成可选项(基于 originalImages,不受筛选影响)
|
||||||
const filterOptions = useMemo(() => {
|
const filterOptions = useMemo(() => {
|
||||||
if (images.length === 0) {
|
if (originalImages.length === 0) {
|
||||||
return { formats: [], sizes: [], hasHorizontal: false, hasVertical: false };
|
return { formats: [], sizes: [], hasHorizontal: false, hasVertical: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ function Header() {
|
|||||||
let hasHorizontal = false;
|
let hasHorizontal = false;
|
||||||
let hasVertical = false;
|
let hasVertical = false;
|
||||||
|
|
||||||
images.forEach(img => {
|
originalImages.forEach(img => {
|
||||||
// 格式
|
// 格式
|
||||||
if (img.format) {
|
if (img.format) {
|
||||||
formats.add(img.format.toLowerCase());
|
formats.add(img.format.toLowerCase());
|
||||||
@@ -199,79 +199,31 @@ function Header() {
|
|||||||
hasHorizontal,
|
hasHorizontal,
|
||||||
hasVertical
|
hasVertical
|
||||||
};
|
};
|
||||||
}, [images]);
|
}, [originalImages]);
|
||||||
|
|
||||||
// 使用 useMemo 缓存筛选结果,避免重复计算
|
// 切换选项 - 同步到全局 store
|
||||||
const filteredResult = useMemo(() => {
|
|
||||||
// 如果没有任何筛选条件,直接返回原始图片
|
|
||||||
if (selectedFormats.length === 0 &&
|
|
||||||
selectedSizes.length === 0 &&
|
|
||||||
!selectedOrientation) {
|
|
||||||
return images;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 预先转换为 Set 以提高查找性能
|
|
||||||
const formatSet = new Set(selectedFormats);
|
|
||||||
const sizeSet = new Set(selectedSizes);
|
|
||||||
|
|
||||||
return images.filter(img => {
|
|
||||||
// 格式筛选
|
|
||||||
if (formatSet.size > 0) {
|
|
||||||
if (!formatSet.has(img.format?.toLowerCase())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 文件大小筛选
|
|
||||||
if (sizeSet.size > 0) {
|
|
||||||
const sizeKB = img.size / 1024;
|
|
||||||
let matchesSize = false;
|
|
||||||
|
|
||||||
for (const range of sizeSet) {
|
|
||||||
if (matchSizeRange(sizeKB, range)) {
|
|
||||||
matchesSize = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!matchesSize) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 横竖图筛选
|
|
||||||
if (selectedOrientation === 'horizontal') {
|
|
||||||
if (img.width <= img.height) return false;
|
|
||||||
} else if (selectedOrientation === 'vertical') {
|
|
||||||
if (img.height <= img.width) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}, [images, selectedFormats, selectedSizes, selectedOrientation]);
|
|
||||||
|
|
||||||
// 注意:过滤逻辑已移至后端,这里的 filteredResult 仅用于显示统计
|
|
||||||
|
|
||||||
// 切换选项
|
|
||||||
const toggleFormat = (format) => {
|
const toggleFormat = (format) => {
|
||||||
setSelectedFormats(prev =>
|
const newFormats = selectedFormats.includes(format)
|
||||||
prev.includes(format) ? prev.filter(f => f !== format) : [...prev, format]
|
? selectedFormats.filter(f => f !== format)
|
||||||
);
|
: [...selectedFormats, format];
|
||||||
|
setFilters({ formats: newFormats });
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleSize = (size) => {
|
const toggleSize = (size) => {
|
||||||
setSelectedSizes(prev =>
|
const newSizes = selectedSizes.includes(size)
|
||||||
prev.includes(size) ? prev.filter(s => s !== size) : [...prev, size]
|
? selectedSizes.filter(s => s !== size)
|
||||||
);
|
: [...selectedSizes, size];
|
||||||
|
setFilters({ sizes: newSizes });
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleOrientation = (orientation) => {
|
const toggleOrientation = (orientation) => {
|
||||||
setSelectedOrientation(prev => prev === orientation ? '' : orientation);
|
const newOrientation = selectedOrientation === orientation ? '' : orientation;
|
||||||
|
setFilters({ orientation: newOrientation });
|
||||||
};
|
};
|
||||||
|
|
||||||
// 清除筛选
|
// 清除筛选
|
||||||
const clearFilters = () => {
|
const clearFilters = () => {
|
||||||
setSelectedFormats([]);
|
setFilters({ formats: [], sizes: [], orientation: '' });
|
||||||
setSelectedSizes([]);
|
|
||||||
setSelectedOrientation('');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleThemeToggle = async () => {
|
const handleThemeToggle = async () => {
|
||||||
|
|||||||
@@ -14,6 +14,36 @@ import FileViewer from './FileViewer';
|
|||||||
// 虚拟滚动阈值:超过此数量启用虚拟滚动
|
// 虚拟滚动阈值:超过此数量启用虚拟滚动
|
||||||
const VIRTUAL_SCROLL_THRESHOLD = 100;
|
const VIRTUAL_SCROLL_THRESHOLD = 100;
|
||||||
|
|
||||||
|
// 解析大小字符串为 KB
|
||||||
|
const parseSizeToKB = (sizeStr) => {
|
||||||
|
const match = sizeStr.match(/^(\d+(?:\.\d+)?)(B|KB|MB|GB)$/);
|
||||||
|
if (!match) return 0;
|
||||||
|
const value = parseFloat(match[1]);
|
||||||
|
const unit = match[2];
|
||||||
|
switch (unit) {
|
||||||
|
case 'B': return value / 1024;
|
||||||
|
case 'KB': return value;
|
||||||
|
case 'MB': return value * 1024;
|
||||||
|
case 'GB': return value * 1024 * 1024;
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 匹配大小范围
|
||||||
|
const matchSizeRange = (sizeKB, range) => {
|
||||||
|
if (range.startsWith('>')) {
|
||||||
|
const minStr = range.substring(1).trim();
|
||||||
|
const minKB = parseSizeToKB(minStr);
|
||||||
|
return sizeKB >= minKB;
|
||||||
|
} else if (range.includes(' - ')) {
|
||||||
|
const [minStr, maxStr] = range.split(' - ').map(s => s.trim());
|
||||||
|
const minKB = parseSizeToKB(minStr);
|
||||||
|
const maxKB = parseSizeToKB(maxStr);
|
||||||
|
return sizeKB >= minKB && sizeKB < maxKB;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
// 加载配置
|
// 加载配置
|
||||||
const LOAD_CONFIG = {
|
const LOAD_CONFIG = {
|
||||||
pageSize: 100, // 每次加载 100 张(更轻量)
|
pageSize: 100, // 每次加载 100 张(更轻量)
|
||||||
@@ -29,8 +59,52 @@ function ImageWaterfall() {
|
|||||||
searchKeywords, filters, appendImages, setImageLoadingState
|
searchKeywords, filters, appendImages, setImageLoadingState
|
||||||
} = useImageStore();
|
} = useImageStore();
|
||||||
|
|
||||||
const filteredImages = images;
|
|
||||||
const { thumbnailHeight, isResizingPanels } = useUIStore();
|
const { thumbnailHeight, isResizingPanels } = useUIStore();
|
||||||
|
|
||||||
|
// 前端筛选逻辑:基于 filters 过滤图片
|
||||||
|
const filteredImages = useMemo(() => {
|
||||||
|
const { formats, sizes, orientation } = filters;
|
||||||
|
|
||||||
|
// 如果没有任何筛选条件,直接返回原始图片
|
||||||
|
if ((!formats || formats.length === 0) &&
|
||||||
|
(!sizes || sizes.length === 0) &&
|
||||||
|
!orientation) {
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
|
return images.filter(img => {
|
||||||
|
// 格式筛选
|
||||||
|
if (formats && formats.length > 0) {
|
||||||
|
if (!formats.includes(img.format?.toLowerCase())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件大小筛选
|
||||||
|
if (sizes && sizes.length > 0) {
|
||||||
|
const sizeKB = img.size / 1024;
|
||||||
|
let matchesSize = false;
|
||||||
|
|
||||||
|
for (const range of sizes) {
|
||||||
|
if (matchSizeRange(sizeKB, range)) {
|
||||||
|
matchesSize = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!matchesSize) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 横竖图筛选
|
||||||
|
if (orientation === 'horizontal') {
|
||||||
|
if (img.width <= img.height) return false;
|
||||||
|
} else if (orientation === 'vertical') {
|
||||||
|
if (img.height <= img.width) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}, [images, filters]);
|
||||||
const containerRef = useRef(null);
|
const containerRef = useRef(null);
|
||||||
const listRef = useRef(null);
|
const listRef = useRef(null);
|
||||||
const [containerWidth, setContainerWidth] = useState(0);
|
const [containerWidth, setContainerWidth] = useState(0);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import Dashboard from './Dashboard';
|
|||||||
|
|
||||||
function MainContent() {
|
function MainContent() {
|
||||||
const { currentLibraryId } = useLibraryStore();
|
const { currentLibraryId } = useLibraryStore();
|
||||||
const { searchKeywords, filters, selectedFolder, setImages, imageLoadingState, images } = useImageStore();
|
const { searchKeywords, filters, selectedFolder, setImages, setOriginalImages, imageLoadingState, images } = useImageStore();
|
||||||
const { scanProgress } = useScanStore();
|
const { scanProgress } = useScanStore();
|
||||||
|
|
||||||
// 使用 ref 跟踪最新的请求上下文
|
// 使用 ref 跟踪最新的请求上下文
|
||||||
@@ -100,9 +100,10 @@ function MainContent() {
|
|||||||
// 标记请求完成
|
// 标记请求完成
|
||||||
requestManager.complete(requestContext.id);
|
requestManager.complete(requestContext.id);
|
||||||
|
|
||||||
// 初次加载:设置图片数据
|
// 初次加载:设置图片数据和原始图片(用于筛选选项)
|
||||||
if (isInitialLoad) {
|
if (isInitialLoad) {
|
||||||
setImages(images);
|
setImages(images);
|
||||||
|
setOriginalImages(images);
|
||||||
}
|
}
|
||||||
|
|
||||||
useImageStore.getState().setImageLoadingState({
|
useImageStore.getState().setImageLoadingState({
|
||||||
@@ -130,7 +131,7 @@ function MainContent() {
|
|||||||
currentRequestContextRef.current = null;
|
currentRequestContextRef.current = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [currentLibraryId, searchKeywords, filters, selectedFolder, setImages, cancelCurrentRequest]);
|
}, [currentLibraryId, searchKeywords, selectedFolder, setImages, setOriginalImages, cancelCurrentRequest]);
|
||||||
|
|
||||||
// 监听文件夹/搜索/筛选变化
|
// 监听文件夹/搜索/筛选变化
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -166,7 +167,7 @@ function MainContent() {
|
|||||||
clearTimeout(debounceTimerRef.current);
|
clearTimeout(debounceTimerRef.current);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [currentLibraryId, searchKeywords, filters, selectedFolder, loadImages, cancelCurrentRequest, setImages]);
|
}, [currentLibraryId, searchKeywords, selectedFolder, loadImages, cancelCurrentRequest, setImages]);
|
||||||
|
|
||||||
// 组件卸载时清理
|
// 组件卸载时清理
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ export const useImageStore = create((set, get) => ({
|
|||||||
searchKeywords: '',
|
searchKeywords: '',
|
||||||
filters: {
|
filters: {
|
||||||
formats: [],
|
formats: [],
|
||||||
minSize: null,
|
sizes: [], // 文件大小范围筛选
|
||||||
maxSize: null,
|
orientation: '', // 横竖图筛选: 'horizontal' | 'vertical' | ''
|
||||||
startDate: null,
|
|
||||||
endDate: null
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 原始图片列表(用于生成筛选选项,不受筛选影响)
|
||||||
|
originalImages: [],
|
||||||
|
|
||||||
// 加载状态
|
// 加载状态
|
||||||
imageLoadingState: {
|
imageLoadingState: {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -37,12 +38,16 @@ export const useImageStore = create((set, get) => ({
|
|||||||
// 图片操作
|
// 图片操作
|
||||||
setImages: (images) => set({ images }),
|
setImages: (images) => set({ images }),
|
||||||
|
|
||||||
|
// 设置原始图片(用于筛选选项)
|
||||||
|
setOriginalImages: (images) => set({ originalImages: images }),
|
||||||
|
|
||||||
// 追加图片(向下滚动时)
|
// 追加图片(向下滚动时)
|
||||||
appendImages: (newImages) => set((state) => ({
|
appendImages: (newImages) => set((state) => ({
|
||||||
images: [...state.images, ...newImages]
|
images: [...state.images, ...newImages],
|
||||||
|
originalImages: [...state.originalImages, ...newImages]
|
||||||
})),
|
})),
|
||||||
|
|
||||||
clearImages: () => set({ images: [] }),
|
clearImages: () => set({ images: [], originalImages: [] }),
|
||||||
|
|
||||||
// 选择操作
|
// 选择操作
|
||||||
setSelectedImage: (image) => set({ selectedImage: image }),
|
setSelectedImage: (image) => set({ selectedImage: image }),
|
||||||
@@ -76,10 +81,8 @@ export const useImageStore = create((set, get) => ({
|
|||||||
searchKeywords: '',
|
searchKeywords: '',
|
||||||
filters: {
|
filters: {
|
||||||
formats: [],
|
formats: [],
|
||||||
minSize: null,
|
sizes: [],
|
||||||
maxSize: null,
|
orientation: ''
|
||||||
startDate: null,
|
|
||||||
endDate: null
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
Generated
+4
-4
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "flypic-monorepo",
|
"name": "flypic-monorepo",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "flypic-monorepo",
|
"name": "flypic-monorepo",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"frontend",
|
"frontend",
|
||||||
"backend"
|
"backend"
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
},
|
},
|
||||||
"backend": {
|
"backend": {
|
||||||
"name": "flypic-backend",
|
"name": "flypic-backend",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^9.2.2",
|
"better-sqlite3": "^9.2.2",
|
||||||
"chokidar": "^3.6.0",
|
"chokidar": "^3.6.0",
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
},
|
},
|
||||||
"frontend": {
|
"frontend": {
|
||||||
"name": "flypic-frontend",
|
"name": "flypic-frontend",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.6.2",
|
"axios": "^1.6.2",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flypic-monorepo",
|
"name": "flypic-monorepo",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "FlyPic - A lightweight and fast image library manager for fnOS",
|
"description": "FlyPic - A lightweight and fast image library manager for fnOS",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
|
|||||||
+25
-21
@@ -101,34 +101,38 @@ console.log(' ⏳ 首次构建需要编译原生模块,约需 1-3 分钟...\
|
|||||||
|
|
||||||
const dockerPath = toDockerPath(packServerDir);
|
const dockerPath = toDockerPath(packServerDir);
|
||||||
|
|
||||||
// 使用 node:22-slim (Debian) 确保 glibc 兼容性
|
// 创建临时安装脚本
|
||||||
const dockerCmd = [
|
const installScript = `#!/bin/sh
|
||||||
'docker run --rm',
|
set -e
|
||||||
`-v "${dockerPath}:/app"`,
|
apt-get update
|
||||||
'-w /app',
|
apt-get install -y python3 make g++ --no-install-recommends
|
||||||
'node:22-slim',
|
npm config set registry https://registry.npmmirror.com
|
||||||
'sh -c "' + [
|
rm -rf node_modules package-lock.json
|
||||||
// 安装编译工具
|
npm install --production
|
||||||
'apt-get update',
|
echo
|
||||||
'apt-get install -y python3 make g++ --no-install-recommends',
|
echo "=== 依赖安装完成 ==="
|
||||||
// 配置 npm 镜像
|
du -sh node_modules/
|
||||||
'npm config set registry https://registry.npmmirror.com',
|
`;
|
||||||
// 清理旧依赖并安装
|
|
||||||
'rm -rf node_modules package-lock.json',
|
const installScriptPath = path.join(packServerDir, 'install.sh');
|
||||||
'npm install --production',
|
fs.writeFileSync(installScriptPath, installScript.replace(/\r\n/g, '\n'), 'utf8');
|
||||||
// 显示结果
|
|
||||||
'echo ""',
|
const dockerCmd = `docker run --rm -v "${dockerPath}:/app" -w /app node:22-slim sh /app/install.sh`;
|
||||||
'echo "=== 依赖安装完成 ==="',
|
|
||||||
'du -sh node_modules/'
|
|
||||||
].join(' && ') + '"'
|
|
||||||
].join(' ');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
run(dockerCmd, { cwd: root });
|
run(dockerCmd, { cwd: root });
|
||||||
|
// 删除临时安装脚本
|
||||||
|
if (fs.existsSync(installScriptPath)) {
|
||||||
|
fs.unlinkSync(installScriptPath);
|
||||||
|
}
|
||||||
console.log('\n ✅ Linux 依赖安装成功');
|
console.log('\n ✅ Linux 依赖安装成功');
|
||||||
console.log(' ✅ 包含 sharp-linux-x64 (glibc 版本)');
|
console.log(' ✅ 包含 sharp-linux-x64 (glibc 版本)');
|
||||||
console.log(' ✅ 包含 better-sqlite3 (Linux 编译版本)\n');
|
console.log(' ✅ 包含 better-sqlite3 (Linux 编译版本)\n');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// 删除临时安装脚本
|
||||||
|
if (fs.existsSync(installScriptPath)) {
|
||||||
|
fs.unlinkSync(installScriptPath);
|
||||||
|
}
|
||||||
console.error('\n ❌ Docker 构建失败');
|
console.error('\n ❌ Docker 构建失败');
|
||||||
console.error(' 错误:', error.message);
|
console.error(' 错误:', error.message);
|
||||||
console.log('\n 请检查:');
|
console.log('\n 请检查:');
|
||||||
|
|||||||
+3
-3
@@ -53,7 +53,7 @@ cd /vol1/1000/flypic
|
|||||||
fnpack build
|
fnpack build
|
||||||
```
|
```
|
||||||
|
|
||||||
成功后会生成 `flypic_0.1.0_all.fpk` 文件。
|
成功后会生成 `flypic_1.0.0_all.fpk` 文件。
|
||||||
|
|
||||||
## 四、安装应用
|
## 四、安装应用
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ fnpack build
|
|||||||
|
|
||||||
### 方法二:命令行安装
|
### 方法二:命令行安装
|
||||||
```bash
|
```bash
|
||||||
appcenter-cli install-fpk flypic_0.1.0_all.fpk
|
appcenter-cli install-fpk flypic_1.0.0_all.fpk
|
||||||
```
|
```
|
||||||
|
|
||||||
## 五、配置应用
|
## 五、配置应用
|
||||||
@@ -125,7 +125,7 @@ flypic/
|
|||||||
### manifest (应用清单)
|
### manifest (应用清单)
|
||||||
```
|
```
|
||||||
appname=flypic
|
appname=flypic
|
||||||
version=0.1.0
|
version=1.0.0
|
||||||
desc=飞图 - 专为飞牛 fnOS 设计的轻量、快速、稳定的图像素材检索浏览应用
|
desc=飞图 - 专为飞牛 fnOS 设计的轻量、快速、稳定的图像素材检索浏览应用
|
||||||
arch=x86_64
|
arch=x86_64
|
||||||
display_name=FlyPic
|
display_name=FlyPic
|
||||||
|
|||||||
Reference in new issue
Block a user