1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Server: Add support for sharing notes via a link

This commit is contained in:
Laurent Cozic
2021-01-29 18:45:11 +00:00
parent 4a847a096b
commit ccbc329cbf
136 changed files with 4713 additions and 5561 deletions

View File

@@ -0,0 +1,34 @@
import { Share, ShareType, Uuid } from '../db';
import { ErrorBadRequest } from '../utils/errors';
import { setQueryParameters } from '../utils/urlUtils';
import BaseModel, { ValidateOptions } from './BaseModel';
export default class ShareModel extends BaseModel<Share> {
public get tableName(): string {
return 'shares';
}
protected async validate(share: Share, _options: ValidateOptions = {}): Promise<Share> {
if ('type' in share && ![ShareType.Link, ShareType.App].includes(share.type)) throw new ErrorBadRequest(`Invalid share type: ${share.type}`);
return share;
}
public async add(type: ShareType, path: string): Promise<Share> {
const fileId: Uuid = await this.models().file({ userId: this.userId }).pathToFileId(path);
const toSave: Share = {
type: type,
file_id: fileId,
owner_id: this.userId,
};
return this.save(toSave);
}
public shareUrl(id: Uuid, query: any = null): string {
return setQueryParameters(`${this.baseUrl}/shares/${id}`, query);
}
}