2020-06-22 13:16:26 +00:00
|
|
|
import Model from "./model";
|
|
|
|
import Api from "../common/api";
|
|
|
|
import {DateTime} from "luxon";
|
2020-04-08 11:24:06 +00:00
|
|
|
|
2020-06-22 13:16:26 +00:00
|
|
|
export default class Link extends Model {
|
2020-04-08 11:24:06 +00:00
|
|
|
getDefaults() {
|
|
|
|
return {
|
2020-06-22 13:16:26 +00:00
|
|
|
UID: "",
|
2020-05-23 18:58:58 +00:00
|
|
|
ShareUID: "",
|
2020-06-22 13:16:26 +00:00
|
|
|
ShareToken: "",
|
|
|
|
ShareExpires: 0,
|
|
|
|
Password: "",
|
|
|
|
HasPassword: false,
|
2020-04-08 11:24:06 +00:00
|
|
|
CanComment: false,
|
|
|
|
CanEdit: false,
|
|
|
|
CreatedAt: "",
|
|
|
|
UpdatedAt: "",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-22 13:16:26 +00:00
|
|
|
url() {
|
|
|
|
let token = this.ShareToken.toLowerCase();
|
|
|
|
|
|
|
|
if(!token) {
|
|
|
|
token = "...";
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${window.location.origin}/s/${token}/${this.ShareUID}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
caption() {
|
|
|
|
return `/s/${this.ShareToken.toLowerCase()}`;
|
|
|
|
}
|
|
|
|
|
2020-04-08 11:24:06 +00:00
|
|
|
getId() {
|
2020-06-22 13:16:26 +00:00
|
|
|
return this.UID;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasId() {
|
|
|
|
return !!this.getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
clone() {
|
|
|
|
return new this.constructor(this.getValues());
|
|
|
|
}
|
|
|
|
|
|
|
|
find(id, params) {
|
|
|
|
return Api.get(this.getEntityResource(id), params).then((response) => Promise.resolve(new this.constructor(response.data)));
|
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
|
|
|
if (this.hasId()) {
|
|
|
|
return this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Api.post(this.constructor.getCollectionResource(), this.getValues()).then((response) => Promise.resolve(this.setValues(response.data)));
|
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
return Api.put(this.getEntityResource(), this.getValues(true)).then((response) => Promise.resolve(this.setValues(response.data)));
|
|
|
|
}
|
|
|
|
|
|
|
|
remove() {
|
|
|
|
return Api.delete(this.getEntityResource()).then(() => Promise.resolve(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
expires() {
|
|
|
|
return DateTime.fromISO(this.UpdatedAt).plus({ seconds: this.ShareExpires }).toLocaleString(DateTime.DATE_SHORT);
|
2020-04-08 11:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static getCollectionResource() {
|
|
|
|
return "links";
|
|
|
|
}
|
|
|
|
|
|
|
|
static getModelName() {
|
|
|
|
return "Link";
|
|
|
|
}
|
|
|
|
}
|