2022-02-11 18:10:12 +09:00

43 lines
1.2 KiB
TypeScript

import autobind from 'autobind-decorator';
import Chart, { KVs } from '../core';
import { DriveFiles } from '@/models/index';
import { Not, IsNull } from 'typeorm';
import { DriveFile } from '@/models/entities/drive-file';
import { name, schema } from './entities/drive';
/**
* ドライブに関するチャート
*/
// eslint-disable-next-line import/no-default-export
export default class DriveChart extends Chart<typeof schema> {
constructor() {
super(name, schema);
}
@autobind
protected async tickMajor(): Promise<Partial<KVs<typeof schema>>> {
return {};
}
@autobind
protected async tickMinor(): Promise<Partial<KVs<typeof schema>>> {
return {};
}
@autobind
public async update(file: DriveFile, isAdditional: boolean): Promise<void> {
const fileSizeKb = file.size / 1000;
await this.commit(file.userHost === null ? {
'local.incCount': isAdditional ? 1 : 0,
'local.incSize': isAdditional ? fileSizeKb : 0,
'local.decCount': isAdditional ? 0 : 1,
'local.decSize': isAdditional ? 0 : fileSizeKb,
} : {
'remote.incCount': isAdditional ? 1 : 0,
'remote.incSize': isAdditional ? fileSizeKb : 0,
'remote.decCount': isAdditional ? 0 : 1,
'remote.decSize': isAdditional ? 0 : fileSizeKb,
});
}
}