You've already forked joplin
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:
34
packages/server/src/models/ShareModel.ts
Normal file
34
packages/server/src/models/ShareModel.ts
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user