Skip to content

Commit

Permalink
Fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmdjiji committed Nov 7, 2024
1 parent 7d0e94f commit dcd499d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
```yaml
version: 1.0 # 配置文件版本,默认 1.0
album:
- name: travel # 相册文件夹名
- name: travel # 相册文件夹名(注意不能为`default`)
friendly_name: 旅行 # 相册显示名
preview: IMG_0001.jpg # 预览图(一定要填写实际存在的文件名)
- name: secret
Expand Down
26 changes: 13 additions & 13 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ const main = async () => {
console.log('Generated meta.json.');

// 创建相册目录
fs.mkdirSync(`${DIST_PATH}/_default`); // 默认相册
fs.mkdirSync(`${DIST_PATH}/_recent`); // 最近相册
fs.mkdirSync(`${DIST_PATH}/default`); // 默认相册
// fs.mkdirSync(`${DIST_PATH}/recent`); // 最近相册
for(const i of album) {
fs.mkdirSync(`${DIST_PATH}/${i.name}`);
if(!i.password) { // 非加密相册
fs.cpSync(`${ALBUM_PATH}/${i.name}`, `${DIST_PATH}/${i.name}/raw`, { recursive: true });
fs.mkdirSync(`${DIST_PATH}/${i.name}/_cache`);
fs.mkdirSync(`${DIST_PATH}/${i.name}/cache`);
fs.readdirSync(`${DIST_PATH}/${i.name}/raw`).forEach(async j => {
await compress(`${DIST_PATH}/${i.name}/raw/${j}`, `${DIST_PATH}/${i.name}/_cache/${j}`);
await compress(`${DIST_PATH}/${i.name}/raw/${j}`, `${DIST_PATH}/${i.name}/cache/${j}`);
});
await compress(`${DIST_PATH}/${i.name}/raw/${i.preview}`, `${DIST_PATH}/${i.name}/preview.jpg`);
} else { // 加密相册
Expand All @@ -104,7 +104,7 @@ const main = async () => {
for(const i of album) {
if(!i.password) { // 非加密相册
const list = await getFiles(`${DIST_PATH}/${i.name}/raw/`);
fs.writeFileSync(`${DIST_PATH}/${i.name}/_meta.json`, JSON.stringify({ count: list.length }));
fs.writeFileSync(`${DIST_PATH}/${i.name}/meta.json`, JSON.stringify({ count: list.length }));
const pageJson = [];
for(const j of list) {
const dimensions = sizeOf(`${DIST_PATH}/${i.name}/raw/${j}`);
Expand All @@ -120,12 +120,12 @@ const main = async () => {
}
const pages = splitArray(pageJson, PHOTO_PER_PAGE);
for(let j in pages) {
fs.writeFileSync(`${DIST_PATH}/${i.name}/_page_${j}.json`, JSON.stringify(pages[j]));
fs.writeFileSync(`${DIST_PATH}/${i.name}/page_${j}.json`, JSON.stringify(pages[j]));
}
} else { // 加密相册
const md5password = md5(String(i.password));
const list = await getFiles(`${DIST_PATH}/${i.name}/${md5password}/`);
fs.writeFileSync(`${DIST_PATH}/${i.name}/_meta.json`, JSON.stringify({
fs.writeFileSync(`${DIST_PATH}/${i.name}/meta.json`, JSON.stringify({
count: list.length - 1, // without probe.json
secret: true,
hint: i.hint,
Expand All @@ -145,24 +145,24 @@ const main = async () => {
}
const pages = splitArray(pageJson, PHOTO_PER_PAGE);
for(let j in pages) {
fs.writeFileSync(`${DIST_PATH}/${i.name}/_page_${j}.json`, JSON.stringify(pages[j]));
fs.writeFileSync(`${DIST_PATH}/${i.name}/page_${j}.json`, JSON.stringify(pages[j]));
}
}
}
const defaultPages = splitArray(defaultJson.sort((a, b) => b.ct - a.ct), PHOTO_PER_PAGE); // 按时间倒序
for(let i in defaultPages) {
fs.writeFileSync(`${DIST_PATH}/_default/_page_${i}.json`, JSON.stringify(defaultPages[i]));
fs.writeFileSync(`${DIST_PATH}/default/page_${i}.json`, JSON.stringify(defaultPages[i]));
}
fs.writeFileSync(`${DIST_PATH}/_default/_meta.json`, JSON.stringify({ count: defaultJson.length }));
fs.writeFileSync(`${DIST_PATH}/default/meta.json`, JSON.stringify({ count: defaultJson.length }));

// const recentJson = defaultJson.sort((a, b) => b.ct - a.ct).slice(0, RECENT_SLICE); // 按时间倒序
// const recentPages = splitArray(recentJson, PHOTO_PER_PAGE);
// for(let i in recentPages) {
// fs.writeFileSync(`${DIST_PATH}/_recent/_page_${i}.json`, JSON.stringify(recentPages[i]));
// fs.writeFileSync(`${DIST_PATH}/_recent/page_${i}.json`, JSON.stringify(recentPages[i]));
// }
// fs.writeFileSync(`${DIST_PATH}/_recent/_meta.json`, JSON.stringify({ count: recentJson.length }));
// fs.writeFileSync(`${DIST_PATH}/_recent/meta.json`, JSON.stringify({ count: recentJson.length }));

console.log('Generated _meta.json and _page.json.');
console.log('Generated meta.json and page.json.');
}

main();
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {
preview_current_obj: '',
preview_password: '',
contentAlbumName: "_default",
contentAlbumName: "default",
contentFriendlyName: "最近项目",
}),
methods: {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ export default {
},
computed: {
album_get_meta_json_name() {
return `${this.base_name}/_meta`;
return `${this.base_name}/meta`;
},
album_get_image_at_current_page_json_name() {
return this.base_name + `/_page_` + String(this.current_page_to_load);
return this.base_name + `/page_` + String(this.current_page_to_load);
}
},
watch: {
Expand Down Expand Up @@ -187,7 +187,7 @@ export default {
this.response_load_new = true;
},
get_thumbnail_image(alumn_name ,image_name) {
return `${utils.publicPath}/api/${alumn_name}/${this.password}_cache/${image_name}`;
return `${utils.publicPath}/api/${alumn_name}/${this.password ? `${this.password}_` : ''}cache/${image_name}`;
},
async initialize() {
Expand Down Expand Up @@ -246,7 +246,7 @@ export default {
// load page 0 first
if (this.page_count > 0) {
const args = await utils.parse_args();
if(args.i) { // 解决多线程异步竞争导致 _page_0_default 抢先加载消耗 count++ 的问题
if(args.i) { // 解决多线程异步竞争导致 page_0default 抢先加载消耗 count++ 的问题
setTimeout(()=>{
this.load_image();
}, 10);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default {
return this.current_photo_filename.replace(/\.[a-z|A-Z|0-9]*$/g, "");
},
thumbnail_path() {
return `${utils.publicPath}/api/${this.current_album_name}/${this.password}_cache/${this.current_photo_filename}`;
return `${utils.publicPath}/api/${this.current_album_name}/${this.password ? `${this.password}_` : ''}cache/${this.current_photo_filename}`;
},
photo_path() {
return `${utils.publicPath}/api/${this.current_album_name}/${this.password || 'raw'}/${this.current_photo_filename}`;
Expand All @@ -48,7 +48,7 @@ export default {
this.$emit('hide-preview');
},
thumbnail_path_at_index(i) {
return `${utils.publicPath}/api/${this.image_list[i].al}/_cache/${this.image_list[i].name}`;
return `${utils.publicPath}/api/${this.image_list[i].al}/${this.image_list[i].name}`;
},
photo_path_at_index(i) {
return `${utils.publicPath}/api/${this.image_list[i].al}/raw/${this.image_list[i].name}`;
Expand Down
10 changes: 5 additions & 5 deletions src/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

<div class="listview normal-menu-ui" style="margin-top: 5px;">
<a v-show="show_banner"
:class="selected('_default')"
@click="switch_album('_default', '最近项目')">
:class="selected('default')"
@click="switch_album('default', '最近项目')">
<span>最近项目</span>
</a>
<!-- <a v-show="show_banner"
:class="selected('_recent')"
@click="switch_album('_recent', '最近项目')">
:class="selected('recent')"
@click="switch_album('recent', '最近项目')">
<span>最近项目</span>
</a> -->
<!-- <a :class="selected('_fav')"
Expand Down Expand Up @@ -77,7 +77,7 @@ export default {
components: { IconSideBar, IconBase, IconExit },
data: () => ({
album_list: [],
selected_album_name: '_default',
selected_album_name: 'default',
show_banner: true,
shouldShowSemiTransparentNavBar: false,
publicPath: utils.publicPath,
Expand Down

0 comments on commit dcd499d

Please sign in to comment.