mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
Add date to markdowns #711
This commit is contained in:
parent
b5dce0a753
commit
c6ba505129
@ -22,6 +22,8 @@ import * as fs from 'fs';
|
|||||||
import {SearchQueryDTO} from '../../../common/entities/SearchQueryDTO';
|
import {SearchQueryDTO} from '../../../common/entities/SearchQueryDTO';
|
||||||
import {PersonEntry} from './enitites/PersonEntry';
|
import {PersonEntry} from './enitites/PersonEntry';
|
||||||
import {PersonJunctionTable} from './enitites/PersonJunctionTable';
|
import {PersonJunctionTable} from './enitites/PersonJunctionTable';
|
||||||
|
import {MDFileEntity} from './enitites/MDFileEntity';
|
||||||
|
import {MDFileDTO} from '../../../common/entities/MDFileDTO';
|
||||||
|
|
||||||
const LOG_TAG = '[IndexingManager]';
|
const LOG_TAG = '[IndexingManager]';
|
||||||
|
|
||||||
@ -292,6 +294,7 @@ export class IndexingManager {
|
|||||||
scannedDirectory: ParentDirectoryDTO
|
scannedDirectory: ParentDirectoryDTO
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const fileRepository = connection.getRepository(FileEntity);
|
const fileRepository = connection.getRepository(FileEntity);
|
||||||
|
const MDfileRepository = connection.getRepository(MDFileEntity);
|
||||||
// save files
|
// save files
|
||||||
const indexedMetaFiles = await fileRepository
|
const indexedMetaFiles = await fileRepository
|
||||||
.createQueryBuilder('file')
|
.createQueryBuilder('file')
|
||||||
@ -319,8 +322,14 @@ export class IndexingManager {
|
|||||||
metaFilesToSave.push(metaFile);
|
metaFilesToSave.push(metaFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await fileRepository.save(metaFilesToSave, {
|
|
||||||
chunk: Math.max(Math.ceil(metaFilesToSave.length / 500), 1),
|
const MDFiles = metaFilesToSave.filter(f => !isNaN((f as MDFileDTO).date));
|
||||||
|
const generalFiles = metaFilesToSave.filter(f => isNaN((f as MDFileDTO).date));
|
||||||
|
await fileRepository.save(generalFiles, {
|
||||||
|
chunk: Math.max(Math.ceil(generalFiles.length / 500), 1),
|
||||||
|
});
|
||||||
|
await MDfileRepository.save(MDFiles, {
|
||||||
|
chunk: Math.max(Math.ceil(MDFiles.length / 500), 1),
|
||||||
});
|
});
|
||||||
await fileRepository.remove(indexedMetaFiles, {
|
await fileRepository.remove(indexedMetaFiles, {
|
||||||
chunk: Math.max(Math.ceil(indexedMetaFiles.length / 500), 1),
|
chunk: Math.max(Math.ceil(indexedMetaFiles.length / 500), 1),
|
||||||
|
@ -22,6 +22,7 @@ import {AlbumBaseEntity} from './enitites/album/AlbumBaseEntity';
|
|||||||
import {SavedSearchEntity} from './enitites/album/SavedSearchEntity';
|
import {SavedSearchEntity} from './enitites/album/SavedSearchEntity';
|
||||||
import {NotificationManager} from '../NotifocationManager';
|
import {NotificationManager} from '../NotifocationManager';
|
||||||
import {PersonJunctionTable} from './enitites/PersonJunctionTable';
|
import {PersonJunctionTable} from './enitites/PersonJunctionTable';
|
||||||
|
import {MDFileEntity} from './enitites/MDFileEntity';
|
||||||
|
|
||||||
const LOG_TAG = '[SQLConnection]';
|
const LOG_TAG = '[SQLConnection]';
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ export class SQLConnection {
|
|||||||
options.entities = [
|
options.entities = [
|
||||||
UserEntity,
|
UserEntity,
|
||||||
FileEntity,
|
FileEntity,
|
||||||
|
MDFileEntity,
|
||||||
PersonJunctionTable,
|
PersonJunctionTable,
|
||||||
PersonEntry,
|
PersonEntry,
|
||||||
MediaEntity,
|
MediaEntity,
|
||||||
@ -76,6 +78,7 @@ export class SQLConnection {
|
|||||||
options.entities = [
|
options.entities = [
|
||||||
UserEntity,
|
UserEntity,
|
||||||
FileEntity,
|
FileEntity,
|
||||||
|
MDFileEntity,
|
||||||
PersonJunctionTable,
|
PersonJunctionTable,
|
||||||
PersonEntry,
|
PersonEntry,
|
||||||
MediaEntity,
|
MediaEntity,
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
import {
|
import {Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, TableInheritance,} from 'typeorm';
|
||||||
Column,
|
import {DirectoryEntity} from './DirectoryEntity';
|
||||||
Entity,
|
import {FileDTO} from '../../../../common/entities/FileDTO';
|
||||||
Index,
|
import {columnCharsetCS} from './EntityUtils';
|
||||||
ManyToOne,
|
|
||||||
PrimaryGeneratedColumn,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { DirectoryEntity } from './DirectoryEntity';
|
|
||||||
import { FileDTO } from '../../../../common/entities/FileDTO';
|
|
||||||
import { columnCharsetCS } from './EntityUtils';
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
|
@TableInheritance({column: {type: 'varchar', name: 'type', length: 16}})
|
||||||
export class FileEntity implements FileDTO {
|
export class FileEntity implements FileDTO {
|
||||||
@Index()
|
@Index()
|
||||||
@PrimaryGeneratedColumn({ unsigned: true })
|
@PrimaryGeneratedColumn({unsigned: true})
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
@Column(columnCharsetCS)
|
@Column(columnCharsetCS)
|
||||||
|
16
src/backend/model/database/enitites/MDFileEntity.ts
Normal file
16
src/backend/model/database/enitites/MDFileEntity.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import {ChildEntity, Column,} from 'typeorm';
|
||||||
|
import {MDFileDTO} from '../../../../common/entities/MDFileDTO';
|
||||||
|
import {FileEntity} from './FileEntity';
|
||||||
|
|
||||||
|
@ChildEntity()
|
||||||
|
export class MDFileEntity extends FileEntity implements MDFileDTO {
|
||||||
|
|
||||||
|
@Column('bigint', {
|
||||||
|
transformer: {
|
||||||
|
from: (v) => parseInt(v, 10),
|
||||||
|
to: (v) => v,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
date: number; // same date as the youngest photo in a folder
|
||||||
|
|
||||||
|
}
|
@ -12,6 +12,7 @@ import {VideoProcessing} from '../fileprocessing/VideoProcessing';
|
|||||||
import {PhotoProcessing} from '../fileprocessing/PhotoProcessing';
|
import {PhotoProcessing} from '../fileprocessing/PhotoProcessing';
|
||||||
import {Utils} from '../../../common/Utils';
|
import {Utils} from '../../../common/Utils';
|
||||||
import {GPXProcessing} from '../fileprocessing/GPXProcessing';
|
import {GPXProcessing} from '../fileprocessing/GPXProcessing';
|
||||||
|
import {MDFileDTO} from '../../../common/entities/MDFileDTO';
|
||||||
|
|
||||||
export class DiskMangerWorker {
|
export class DiskMangerWorker {
|
||||||
public static calcLastModified(stat: Stats): number {
|
public static calcLastModified(stat: Stats): number {
|
||||||
@ -227,6 +228,7 @@ export class DiskMangerWorker {
|
|||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
directory.metaFile.push({
|
directory.metaFile.push({
|
||||||
name: file,
|
name: file,
|
||||||
directory: null,
|
directory: null,
|
||||||
@ -244,6 +246,12 @@ export class DiskMangerWorker {
|
|||||||
directory.oldestMedia = Math.max(m.metadata.creationDate, directory.oldestMedia);
|
directory.oldestMedia = Math.max(m.metadata.creationDate, directory.oldestMedia);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
directory.metaFile.forEach(mf => {
|
||||||
|
if (DiskMangerWorker.isMarkdown(mf.name)) {
|
||||||
|
(mf as MDFileDTO).date = directory.youngestMedia;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return directory;
|
return directory;
|
||||||
@ -264,6 +272,12 @@ export class DiskMangerWorker {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static isMarkdown(fullPath: string): boolean {
|
||||||
|
const extension = path.extname(fullPath).toLowerCase();
|
||||||
|
|
||||||
|
return extension == '.md';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DirectoryScanSettings {
|
export interface DirectoryScanSettings {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/**
|
/**
|
||||||
* This version indicates that the sql/entities/*Entity.ts files got changed and the db needs to be recreated
|
* This version indicates that the sql/entities/*Entity.ts files got changed and the db needs to be recreated
|
||||||
*/
|
*/
|
||||||
export const DataStructureVersion = 33;
|
export const DataStructureVersion = 34;
|
||||||
|
10
src/common/entities/MDFileDTO.ts
Normal file
10
src/common/entities/MDFileDTO.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import {DirectoryPathDTO} from './DirectoryDTO';
|
||||||
|
import {FileDTO} from './FileDTO';
|
||||||
|
|
||||||
|
export interface MDFileDTO extends FileDTO {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
directory: DirectoryPathDTO;
|
||||||
|
date: number;
|
||||||
|
}
|
||||||
|
|
1
test/backend/assets/index.md
Normal file
1
test/backend/assets/index.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
This is a test md.
|
@ -635,6 +635,32 @@ describe('IndexingManager', (sqlHelper: DBTestHelper) => {
|
|||||||
expect(selected.media.length).to.equal(subDir.media.length);
|
expect(selected.media.length).to.equal(subDir.media.length);
|
||||||
}) as any).timeout(40000);
|
}) as any).timeout(40000);
|
||||||
|
|
||||||
|
it('should save .md with date', async () => {
|
||||||
|
Config.Server.Threading.enabled = false;
|
||||||
|
Config.Album.enabled = true;
|
||||||
|
Config.Faces.enabled = true;
|
||||||
|
|
||||||
|
Config.Media.folder = path.join(__dirname, '/../../../assets');
|
||||||
|
ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets');
|
||||||
|
const im = new IndexingManagerTest();
|
||||||
|
const gm = new GalleryManagerTest();
|
||||||
|
|
||||||
|
const d = await DiskManager.scanDirectory('/');
|
||||||
|
|
||||||
|
await im.saveToDB(d);
|
||||||
|
|
||||||
|
const dir = await gm.listDirectory('/');
|
||||||
|
expect(dir.metaFile).to.be.an('array');
|
||||||
|
|
||||||
|
expect(dir.metaFile).to.be.deep.equal([
|
||||||
|
{
|
||||||
|
date: 1126455782000,
|
||||||
|
id: 1,
|
||||||
|
name: 'index.md'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
DBTestHelper.savedDescribe('Test listDirectory', () => {
|
DBTestHelper.savedDescribe('Test listDirectory', () => {
|
||||||
const statSync = fs.statSync;
|
const statSync = fs.statSync;
|
||||||
let dirTime = 0;
|
let dirTime = 0;
|
||||||
@ -691,7 +717,6 @@ describe('IndexingManager', (sqlHelper: DBTestHelper) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
DBTestHelper.savedDescribe('should index .pg2conf', () => {
|
DBTestHelper.savedDescribe('should index .pg2conf', () => {
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user