-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
248 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import request from '@/utils/request' | ||
|
||
export const getStatistic = () => | ||
request({ | ||
url: `admin/statistic`, | ||
method: 'GET', | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
const { filesize } = require('filesize'); | ||
// const getFolderSize = require('get-folder-size'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
async function getFileSize(path) { | ||
try { | ||
const { size } = await fs.promises.stat(path); | ||
return size; | ||
} catch (e) { | ||
return 0; | ||
} | ||
} | ||
|
||
module.exports = app => { | ||
class StatisticController extends app.Controller { | ||
async getAvailablePhotoList(ctx) { | ||
let photo_list = []; | ||
|
||
const galleries = await ctx.model.Gallery.findAll(); | ||
|
||
for (const gallery of galleries) { | ||
const photos = await ctx.model.Photo.findAll({ | ||
where: { gallery_id: gallery.id }, | ||
}); | ||
photo_list = [ ...photo_list, ...photos ]; | ||
} | ||
|
||
return photo_list; | ||
} | ||
async getAllMemberList(ctx) { | ||
const member_list = await ctx.model.Member.findAll({}); | ||
return member_list; | ||
} | ||
|
||
async getSrcTotalSize(ctx, image_path, src_list) { | ||
const full_src_list = src_list | ||
.map(ctx.app.serviceClasses.image.allFilename) | ||
.flat(); | ||
|
||
let total = 0; | ||
for (const src of full_src_list) { | ||
const size = await getFileSize(path.join(image_path, src)); | ||
total = total + size; | ||
} | ||
return total; | ||
} | ||
|
||
async show(ctx) { | ||
const [ available_photo_list, member_list ] = await Promise.all([ | ||
this.getAvailablePhotoList(ctx), | ||
this.getAllMemberList(ctx), | ||
]); | ||
|
||
const src_list = [ | ||
...available_photo_list.map(p => p.src), | ||
...member_list.map(m => m.avatar_src), | ||
]; | ||
|
||
const { imageSavePath, imageThumbSavePath } = ctx.app.config; | ||
|
||
const [ src_total_size_raw, thumb_total_size_raw ] = await Promise.all([ | ||
this.getSrcTotalSize(ctx, imageSavePath, src_list), | ||
this.getSrcTotalSize(ctx, imageThumbSavePath, src_list), | ||
]); | ||
|
||
ctx.backData(200, { | ||
available_photo_count: available_photo_list.length, | ||
src_total_size: filesize(src_total_size_raw), | ||
thumb_total_size: filesize(thumb_total_size_raw), | ||
}); | ||
} | ||
} | ||
return StatisticController; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.