refactor: convertFlags to utils

cache
Varun Patil 2022-10-15 20:28:40 -07:00
parent a20edc67bb
commit 2b9e7ee5b7
2 changed files with 29 additions and 20 deletions

View File

@ -718,26 +718,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
}
// Flag conversion
if (photo.isvideo) {
photo.flag |= this.c.FLAG_IS_VIDEO;
delete photo.isvideo;
}
if (photo.isfavorite) {
photo.flag |= this.c.FLAG_IS_FAVORITE;
delete photo.isfavorite;
}
if (photo.isfolder) {
photo.flag |= this.c.FLAG_IS_FOLDER;
delete photo.isfolder;
}
if (photo.isface) {
photo.flag |= this.c.FLAG_IS_FACE;
delete photo.isface;
}
if (photo.istag) {
photo.flag |= this.c.FLAG_IS_TAG;
delete photo.istag;
}
utils.convertFlags(photo);
// Get aspect ratio
photo.dispWp = utils.round(100 * jbox.width / this.rowWidth, 2);

View File

@ -1,4 +1,5 @@
import { getCanonicalLocale } from "@nextcloud/l10n";
import { IPhoto } from "../types";
// Memoize the result of short date conversions
// These operations are surprisingly expensive
@ -108,6 +109,33 @@ export function roundHalf(num: number) {
return Math.round(num * 2) / 2;
}
/**
* Convert server-side flags to bitmask
* @param photo Photo to process
*/
export function convertFlags(photo: IPhoto) {
if (photo.isvideo) {
photo.flag |= constants.c.FLAG_IS_VIDEO;
delete photo.isvideo;
}
if (photo.isfavorite) {
photo.flag |= constants.c.FLAG_IS_FAVORITE;
delete photo.isfavorite;
}
if (photo.isfolder) {
photo.flag |= constants.c.FLAG_IS_FOLDER;
delete photo.isfolder;
}
if (photo.isface) {
photo.flag |= constants.c.FLAG_IS_FACE;
delete photo.isface;
}
if (photo.istag) {
photo.flag |= constants.c.FLAG_IS_TAG;
delete photo.istag;
}
}
/** Global constants */
export const constants = {
c: {