Skip to content

Commit

Permalink
fix: local image server
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish committed Mar 2, 2024
1 parent b609b32 commit 46a05b3
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 45 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ node_modules
.idea/
*.log
.env
*.zip

apps/web/public/assets/img/
packages/core/src/constants/data.mjs

.vercel

.vercel
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,19 @@
#### 处理导出后的数据

完成后将导出包含微博数据的 `weibo-data.json` 和包含微博图片链接的 `imgs.csv`,这两个文件。以及自动下载 `preview.zip`解压后里面包含了用于预览的 HTML 文件和一些工具脚本
完成后将导出包含微博数据的 `weibo-data.json` 和包含微博图片链接的 `imgs.csv`,这两个文件。以及自动下载 `scripts.zip`解压后里面包含了用于下载图片和查看图片工具脚本

1. 首先将 imgs.csv 复制到 preview 文件夹中(用于下载微博图片)
1. 首先将 imgs.csv 复制到 scripts 文件夹中(用于下载微博图片)

2. 然后使用 `download.mjs` 来下载图片到本地(这一步也可以跳过,在预览页中的设置中启用“使用远程 CDN”即可,但为了永久保存图片不被突然被夹掉,还是建议下载图片)

preview 文件夹中包含了交互式一键运行的 `run.bat` 脚本(感谢 [@HayashiKaori] [#20]),按里面的提示运行即可
scripts 文件夹中包含了交互式一键运行的 `run.bat` 脚本(感谢 [@HayashiKaori] [#20]),按里面的提示运行即可

> 其中,运行下载图片脚本之前需要安装 Node.js,可以在 [Node.js 官网] 下载最新版本,然后找教程配置系统环境
#### 查看结果

目前有两种方式预览备份后的微博

- 使用我们提供的在线预览页面:https://weibo.chilfish.top (推荐)。点击右上角的设置按钮,按提示导入刚才导出的 `weibo-data.json` 即可查看(也支持旧版导出的 data.mjs)
- 使用本地预览。不支持直接点击 index.html 来查看,需要启动本地的服务器。运行 `run.bat` 脚本查看
访问我们提供的在线预览平台:https://weibo.chilfish.top 。点击右上角的设置按钮,按提示导入刚才导出的 `weibo-data.json` 即可查看(也支持旧版导出的 `data.mjs`

不过正在开发桌面版app,届时将不再需要这些复杂的操作,直接双击打开即可查看

Expand Down
10 changes: 3 additions & 7 deletions apps/monkey/src/utils/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import JSZip from 'jszip'
import { saveAs } from 'file-saver'
import type { Post } from '@types'

const version = '0.3.0'

function imgsParser(posts: Post[]): Set<string> {
const imgs = posts
.map((post) => {
Expand All @@ -21,10 +19,7 @@ function imgsParser(posts: Post[]): Set<string> {
return new Set(imgs)
}

/**
* 预览压缩包下载地址
*/
const previewZip = `https://github.com/Chilfish/Weibo-archiver/releases/download/v${version}/preview.zip`
const scripts = 'https://raw.githubusercontent.com/Chilfish/Weibo-archiver/monkey/script.zip'

export function exportData(posts: Post[]) {
// 只能固定版本在 3.9.1,因为油猴的升级
Expand All @@ -45,5 +40,6 @@ export function exportData(posts: Post[]) {
window.$message.success('导出成功,正在下载数据...')
saveAs(zipFile, 'weibo-archiver.zip')
})
saveAs(previewZip, 'preview.zip')

saveAs(scripts, 'scripts.zip')
}
3 changes: 1 addition & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"typecheck": "vue-tsc --noEmit"
},
"dependencies": {
"@weibo-archiver/ui": "workspace:^",
"vite-plugin-static-copy": "^1.0.1"
"@weibo-archiver/ui": "workspace:^"
}
}
11 changes: 1 addition & 10 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path'
import { defineConfig, normalizePath } from 'vite'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import { defineConfig } from 'vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'

import Components from 'unplugin-vue-components/vite'
Expand Down Expand Up @@ -35,13 +34,5 @@ export default defineConfig({
NaiveUiResolver(),
],
}),
viteStaticCopy({
targets: [
{
src: normalizePath(path.resolve(root, 'scripts/*')),
dest: normalizePath(path.resolve(root, 'dist/preview')),
},
],
}),
],
})
2 changes: 1 addition & 1 deletion packages/core/src/utils/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function replaceImg(img: string) {
const fileName = `${prefix}-${name}`

if (imgHost === '/')
return `/assets/img/${fileName}`
return `http://localhost:3000/${fileName}`

const fixedBase = imgHost.endsWith('/') ? imgHost : `${imgHost}/`
return `${fixedBase}${fileName}`
Expand Down
Loading

0 comments on commit 46a05b3

Please sign in to comment.