mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 19:53:59 -05:00
Reformat code by yarn format
Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
a7f35aaeec
commit
c2b6c6fe49
8 changed files with 73 additions and 62 deletions
|
@ -79,9 +79,9 @@ export class MeController {
|
||||||
@UseGuards(TokenAuthGuard)
|
@UseGuards(TokenAuthGuard)
|
||||||
@Get('notes')
|
@Get('notes')
|
||||||
async getMyNotes(@Request() req): Promise<NoteMetadataDto[]> {
|
async getMyNotes(@Request() req): Promise<NoteMetadataDto[]> {
|
||||||
const notes = await this.notesService.getUserNotes(req.user)
|
const notes = await this.notesService.getUserNotes(req.user);
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
notes.map(note => this.notesService.toNoteMetadataDto(note))
|
notes.map((note) => this.notesService.toNoteMetadataDto(note)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ export class MediaController {
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@UploadedFile() file: MulterFile,
|
@UploadedFile() file: MulterFile,
|
||||||
@Headers('HedgeDoc-Note') noteId: string,
|
@Headers('HedgeDoc-Note') noteId: string,
|
||||||
) : Promise<MediaUploadUrlDto> {
|
): Promise<MediaUploadUrlDto> {
|
||||||
const username = req.user.userName;
|
const username = req.user.userName;
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Recieved filename '${file.originalname}' for note '${noteId}' from user '${username}'`,
|
`Recieved filename '${file.originalname}' for note '${noteId}' from user '${username}'`,
|
||||||
|
@ -60,7 +60,7 @@ export class MediaController {
|
||||||
username,
|
username,
|
||||||
noteId,
|
noteId,
|
||||||
);
|
);
|
||||||
return this.mediaService.toMediaUploadUrlDto(url)
|
return this.mediaService.toMediaUploadUrlDto(url);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ClientError || e instanceof NotInDBError) {
|
if (e instanceof ClientError || e instanceof NotInDBError) {
|
||||||
throw new BadRequestException(e.message);
|
throw new BadRequestException(e.message);
|
||||||
|
@ -71,7 +71,10 @@ export class MediaController {
|
||||||
|
|
||||||
@UseGuards(TokenAuthGuard)
|
@UseGuards(TokenAuthGuard)
|
||||||
@Delete(':filename')
|
@Delete(':filename')
|
||||||
async deleteMedia(@Request() req, @Param('filename') filename: string) : Promise<void> {
|
async deleteMedia(
|
||||||
|
@Request() req,
|
||||||
|
@Param('filename') filename: string,
|
||||||
|
): Promise<void> {
|
||||||
const username = req.user.userName;
|
const username = req.user.userName;
|
||||||
try {
|
try {
|
||||||
await this.mediaService.deleteFile(filename, username);
|
await this.mediaService.deleteFile(filename, username);
|
||||||
|
|
|
@ -17,7 +17,7 @@ export class MonitoringController {
|
||||||
|
|
||||||
@UseGuards(TokenAuthGuard)
|
@UseGuards(TokenAuthGuard)
|
||||||
@Get()
|
@Get()
|
||||||
getStatus() : Promise<ServerStatusDto> {
|
getStatus(): Promise<ServerStatusDto> {
|
||||||
// TODO: toServerStatusDto.
|
// TODO: toServerStatusDto.
|
||||||
return this.monitoringService.getServerStatus();
|
return this.monitoringService.getServerStatus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,10 @@ import {
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { NotInDBError } from '../../../errors/errors';
|
import { NotInDBError } from '../../../errors/errors';
|
||||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
import { NotePermissionsDto, NotePermissionsUpdateDto } from '../../../notes/note-permissions.dto';
|
import {
|
||||||
|
NotePermissionsDto,
|
||||||
|
NotePermissionsUpdateDto,
|
||||||
|
} from '../../../notes/note-permissions.dto';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
import { RevisionsService } from '../../../revisions/revisions.service';
|
import { RevisionsService } from '../../../revisions/revisions.service';
|
||||||
import { MarkdownBody } from '../../utils/markdownbody-decorator';
|
import { MarkdownBody } from '../../utils/markdownbody-decorator';
|
||||||
|
@ -43,11 +46,14 @@ export class NotesController {
|
||||||
|
|
||||||
@UseGuards(TokenAuthGuard)
|
@UseGuards(TokenAuthGuard)
|
||||||
@Post()
|
@Post()
|
||||||
async createNote(@Request() req, @MarkdownBody() text: string): Promise<NoteDto> {
|
async createNote(
|
||||||
|
@Request() req,
|
||||||
|
@MarkdownBody() text: string,
|
||||||
|
): Promise<NoteDto> {
|
||||||
// ToDo: provide user for createNoteDto
|
// ToDo: provide user for createNoteDto
|
||||||
this.logger.debug('Got raw markdown:\n' + text);
|
this.logger.debug('Got raw markdown:\n' + text);
|
||||||
return this.noteService.toNoteDto(
|
return this.noteService.toNoteDto(
|
||||||
await this.noteService.createNote(text, undefined, req.user)
|
await this.noteService.createNote(text, undefined, req.user),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,17 +67,20 @@ export class NotesController {
|
||||||
// ToDo: check if user is allowed to view this note
|
// ToDo: check if user is allowed to view this note
|
||||||
this.logger.debug('Got raw markdown:\n' + text);
|
this.logger.debug('Got raw markdown:\n' + text);
|
||||||
return this.noteService.toNoteDto(
|
return this.noteService.toNoteDto(
|
||||||
await this.noteService.createNote(text, noteAlias, req.user)
|
await this.noteService.createNote(text, noteAlias, req.user),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(TokenAuthGuard)
|
@UseGuards(TokenAuthGuard)
|
||||||
@Get(':noteIdOrAlias')
|
@Get(':noteIdOrAlias')
|
||||||
async getNote(@Request() req, @Param('noteIdOrAlias') noteIdOrAlias: string) : Promise<NoteDto> {
|
async getNote(
|
||||||
|
@Request() req,
|
||||||
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
): Promise<NoteDto> {
|
||||||
// ToDo: check if user is allowed to view this note
|
// ToDo: check if user is allowed to view this note
|
||||||
try {
|
try {
|
||||||
return this.noteService.toNoteDto(
|
return this.noteService.toNoteDto(
|
||||||
await this.noteService.getNoteByIdOrAlias(noteIdOrAlias)
|
await this.noteService.getNoteByIdOrAlias(noteIdOrAlias),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
|
@ -107,12 +116,12 @@ export class NotesController {
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
@MarkdownBody() text: string,
|
@MarkdownBody() text: string,
|
||||||
) : Promise<NoteDto> {
|
): Promise<NoteDto> {
|
||||||
// ToDo: check if user is allowed to change this note
|
// ToDo: check if user is allowed to change this note
|
||||||
this.logger.debug('Got raw markdown:\n' + text);
|
this.logger.debug('Got raw markdown:\n' + text);
|
||||||
try {
|
try {
|
||||||
return this.noteService.toNoteDto(
|
return this.noteService.toNoteDto(
|
||||||
await this.noteService.updateNoteByIdOrAlias(noteIdOrAlias, text)
|
await this.noteService.updateNoteByIdOrAlias(noteIdOrAlias, text),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
|
@ -128,7 +137,7 @@ export class NotesController {
|
||||||
async getNoteContent(
|
async getNoteContent(
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
) : Promise<string> {
|
): Promise<string> {
|
||||||
// ToDo: check if user is allowed to view this notes content
|
// ToDo: check if user is allowed to view this notes content
|
||||||
try {
|
try {
|
||||||
return await this.noteService.getNoteContent(noteIdOrAlias);
|
return await this.noteService.getNoteContent(noteIdOrAlias);
|
||||||
|
@ -145,11 +154,11 @@ export class NotesController {
|
||||||
async getNoteMetadata(
|
async getNoteMetadata(
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
) : Promise<NoteMetadataDto> {
|
): Promise<NoteMetadataDto> {
|
||||||
// ToDo: check if user is allowed to view this notes metadata
|
// ToDo: check if user is allowed to view this notes metadata
|
||||||
try {
|
try {
|
||||||
return this.noteService.toNoteMetadataDto(
|
return this.noteService.toNoteMetadataDto(
|
||||||
await this.noteService.getNoteByIdOrAlias(noteIdOrAlias)
|
await this.noteService.getNoteByIdOrAlias(noteIdOrAlias),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
|
@ -165,14 +174,11 @@ export class NotesController {
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
@Body() updateDto: NotePermissionsUpdateDto,
|
@Body() updateDto: NotePermissionsUpdateDto,
|
||||||
) : Promise<NotePermissionsDto> {
|
): Promise<NotePermissionsDto> {
|
||||||
// ToDo: check if user is allowed to view this notes permissions
|
// ToDo: check if user is allowed to view this notes permissions
|
||||||
try {
|
try {
|
||||||
return this.noteService.toNotePermissionsDto(
|
return this.noteService.toNotePermissionsDto(
|
||||||
await this.noteService.updateNotePermissions(
|
await this.noteService.updateNotePermissions(noteIdOrAlias, updateDto),
|
||||||
noteIdOrAlias,
|
|
||||||
updateDto,
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
|
@ -187,14 +193,16 @@ export class NotesController {
|
||||||
async getNoteRevisions(
|
async getNoteRevisions(
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
) : Promise<RevisionMetadataDto[]> {
|
): Promise<RevisionMetadataDto[]> {
|
||||||
// ToDo: check if user is allowed to view this notes revisions
|
// ToDo: check if user is allowed to view this notes revisions
|
||||||
try {
|
try {
|
||||||
const revisions = await this.revisionsService.getAllRevisions(
|
const revisions = await this.revisionsService.getAllRevisions(
|
||||||
noteIdOrAlias,
|
noteIdOrAlias,
|
||||||
);
|
);
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
revisions.map(revision => this.revisionsService.toRevisionMetadataDto(revision))
|
revisions.map((revision) =>
|
||||||
|
this.revisionsService.toRevisionMetadataDto(revision),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
|
@ -210,14 +218,11 @@ export class NotesController {
|
||||||
@Request() req,
|
@Request() req,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
@Param('revisionId') revisionId: number,
|
@Param('revisionId') revisionId: number,
|
||||||
) : Promise<RevisionDto> {
|
): Promise<RevisionDto> {
|
||||||
// ToDo: check if user is allowed to view this notes revision
|
// ToDo: check if user is allowed to view this notes revision
|
||||||
try {
|
try {
|
||||||
return this.revisionsService.toRevisionDto(
|
return this.revisionsService.toRevisionDto(
|
||||||
await this.revisionsService.getRevision(
|
await this.revisionsService.getRevision(noteIdOrAlias, revisionId),
|
||||||
noteIdOrAlias,
|
|
||||||
revisionId,
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
|
|
|
@ -4,11 +4,9 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import { IsString } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
|
|
||||||
export class MediaUploadUrlDto {
|
export class MediaUploadUrlDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
link: string
|
link: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,11 @@ export class MediaService {
|
||||||
return allowedTypes.includes(mimeType);
|
return allowedTypes.includes(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async saveFile(fileBuffer: Buffer, username: string, noteId: string): Promise<string> {
|
public async saveFile(
|
||||||
|
fileBuffer: Buffer,
|
||||||
|
username: string,
|
||||||
|
noteId: string,
|
||||||
|
): Promise<string> {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`Saving file for note '${noteId}' and user '${username}'`,
|
`Saving file for note '${noteId}' and user '${username}'`,
|
||||||
'saveFile',
|
'saveFile',
|
||||||
|
@ -137,6 +141,6 @@ export class MediaService {
|
||||||
toMediaUploadUrlDto(url: string): MediaUploadUrlDto {
|
toMediaUploadUrlDto(url: string): MediaUploadUrlDto {
|
||||||
return {
|
return {
|
||||||
link: url,
|
link: url,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ export class NotesService {
|
||||||
{
|
{
|
||||||
id: 'foobar-barfoo',
|
id: 'foobar-barfoo',
|
||||||
alias: null,
|
alias: null,
|
||||||
shortid: "abc",
|
shortid: 'abc',
|
||||||
owner: user,
|
owner: user,
|
||||||
description: 'Very descriptive text.',
|
description: 'Very descriptive text.',
|
||||||
userPermissions: [],
|
userPermissions: [],
|
||||||
|
@ -125,7 +125,10 @@ export class NotesService {
|
||||||
return await this.noteRepository.remove(note);
|
return await this.noteRepository.remove(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateNoteByIdOrAlias(noteIdOrAlias: string, noteContent: string): Promise<Note> {
|
async updateNoteByIdOrAlias(
|
||||||
|
noteIdOrAlias: string,
|
||||||
|
noteContent: string,
|
||||||
|
): Promise<Note> {
|
||||||
const note = await this.getNoteByIdOrAlias(noteIdOrAlias);
|
const note = await this.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
const revisions = await note.revisions;
|
const revisions = await note.revisions;
|
||||||
//TODO: Calculate patch
|
//TODO: Calculate patch
|
||||||
|
@ -140,27 +143,27 @@ export class NotesService {
|
||||||
): Note {
|
): Note {
|
||||||
this.logger.warn('Using hardcoded data!');
|
this.logger.warn('Using hardcoded data!');
|
||||||
return {
|
return {
|
||||||
id: 'foobar-barfoo',
|
id: 'foobar-barfoo',
|
||||||
alias: null,
|
alias: null,
|
||||||
shortid: "abc",
|
shortid: 'abc',
|
||||||
owner: {
|
owner: {
|
||||||
authTokens: [],
|
authTokens: [],
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
displayName: 'hardcoded',
|
displayName: 'hardcoded',
|
||||||
id: '1',
|
id: '1',
|
||||||
identities: [],
|
identities: [],
|
||||||
ownedNotes: [],
|
ownedNotes: [],
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
userName: 'Testy',
|
userName: 'Testy',
|
||||||
},
|
},
|
||||||
description: 'Very descriptive text.',
|
description: 'Very descriptive text.',
|
||||||
userPermissions: [],
|
userPermissions: [],
|
||||||
groupPermissions: [],
|
groupPermissions: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
revisions: Promise.resolve([]),
|
revisions: Promise.resolve([]),
|
||||||
authorColors: [],
|
authorColors: [],
|
||||||
title: 'Title!',
|
title: 'Title!',
|
||||||
viewcount: 42,
|
viewcount: 42,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +183,7 @@ export class NotesService {
|
||||||
group: noteGroupPermission.group,
|
group: noteGroupPermission.group,
|
||||||
canEdit: noteGroupPermission.canEdit,
|
canEdit: noteGroupPermission.canEdit,
|
||||||
})),
|
})),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async toNoteMetadataDto(note: Note): Promise<NoteMetadataDto> {
|
async toNoteMetadataDto(note: Note): Promise<NoteMetadataDto> {
|
||||||
|
|
|
@ -24,9 +24,7 @@ export class RevisionsService {
|
||||||
this.logger.setContext(RevisionsService.name);
|
this.logger.setContext(RevisionsService.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllRevisions(
|
async getAllRevisions(noteIdOrAlias: string): Promise<Revision[]> {
|
||||||
noteIdOrAlias: string,
|
|
||||||
): Promise<Revision[]> {
|
|
||||||
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
|
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
return await this.revisionRepository.find({
|
return await this.revisionRepository.find({
|
||||||
where: {
|
where: {
|
||||||
|
@ -88,7 +86,7 @@ export class RevisionsService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
createRevision(content: string) : Revision {
|
createRevision(content: string): Revision {
|
||||||
// TODO: Add previous revision
|
// TODO: Add previous revision
|
||||||
// TODO: Calculate patch
|
// TODO: Calculate patch
|
||||||
// TODO: Save metadata
|
// TODO: Save metadata
|
||||||
|
|
Loading…
Reference in a new issue