Initial commit, not complete

+ Create new sql column for file last modified time (flmt)
+ Implement uploading of flmt to server
+ Implement flmt in post model
+ Ability to read flmt thru API
+ New section in post_readonly_sidebar that shows flmt
! Somehow flmt is the same as post creation time
! Implement proper alembic migrations
! Implement ability to sort by flmt
! Implement ability to filter posts by flmt
! Code cleanup
~ Polish post sidebar
~ Implement flmt visibility in post listing hover text
~ Implement function in misc.js that formats to absolute date
This commit is contained in:
Luxray5474 2020-08-21 23:32:15 -04:00
parent 9189842524
commit 239bc0a14d
8 changed files with 32 additions and 0 deletions

View file

@ -26,6 +26,11 @@
<%= ctx.makeRelativeTime(ctx.post.creationTime) %>
</section>
<section class='file-last-modified-time'>
Source file last modified
<%= ctx.makeRelativeTime(ctx.post.fileLastModifiedTime) %>
</section>
<% if (ctx.enableSafety) { %>
<section class='safety'>
<i class='fa fa-circle safety-<%- ctx.post.safety %>'></i><!--

View file

@ -177,6 +177,7 @@ class PostUploadController {
if (uploadable.url) {
post.source = uploadable.url;
}
post.fileLastModifiedTime = uploadable.file.lastModified; // The client already reads the data anyway, which is convenient
return post;
}
}

View file

@ -42,6 +42,10 @@ class Post extends events.EventTarget {
return this._creationTime;
}
get fileLastModifiedTime() {
return this._fileLastModifiedTime;
}
get user() {
return this._user;
}
@ -269,6 +273,9 @@ class Post extends events.EventTarget {
if (this._source !== this._orig._source) {
detail.source = this._source;
}
if (this._fileLastModifiedTime !== this._orig._fileLastModifiedTime) {
detail.fileLastModifiedTime = this._fileLastModifiedTime;
}
let apiPromise = this._id
? api.put(uri.formatApiLink("post", this.id), detail, files)
@ -460,6 +467,7 @@ class Post extends events.EventTarget {
_type: response.type,
_mimeType: response.mimeType,
_creationTime: response.creationTime,
_fileLastModifiedTime: response.fileLastModifiedTime,
_user: response.user,
_safety: response.safety,
_contentUrl: response.contentUrl,

View file

@ -82,6 +82,10 @@ class File extends Uploadable {
return this.file.type;
}
get fileLastModifiedTime() {
return this.file.fileLastModifiedTime;
}
get previewUrl() {
return this._previewUrl;
}
@ -216,6 +220,7 @@ class PostUploadView extends events.EventTarget {
duplicatesFound++;
continue;
}
console.log(uploadable)
this._uploadables.push(uploadable);
this._emit("change");
this._renderRowNode(uploadable);

View file

@ -1,3 +1,4 @@
import time
from datetime import datetime
from typing import Dict, List, Optional

View file

@ -169,6 +169,7 @@ class PostSerializer(serialization.BaseSerializer):
"version": self.serialize_version,
"creationTime": self.serialize_creation_time,
"lastEditTime": self.serialize_last_edit_time,
"fileLastModifiedTime": self.serialize_file_last_modified_time,
"safety": self.serialize_safety,
"source": self.serialize_source,
"type": self.serialize_type,
@ -212,6 +213,9 @@ class PostSerializer(serialization.BaseSerializer):
def serialize_last_edit_time(self) -> Any:
return self.post.last_edit_time
def serialize_file_last_modified_time(self) -> Any:
return self.post.file_last_modified_time
def serialize_safety(self) -> Any:
return SAFETY_MAP[self.post.safety]
@ -408,6 +412,7 @@ def create_post(
post.safety = model.Post.SAFETY_SAFE
post.user = user
post.creation_time = datetime.utcnow()
post.file_last_modified_time = datetime.utcnow()
post.flags = []
post.type = ""
@ -421,6 +426,11 @@ def create_post(
return post, new_tags
def update_post_file_last_modified_time(post: model.Post, timestamp: int) -> None:
assert post
file_last_modified_time = datetime.fromtimestamp(ctx.get_param_as_int("lastModified", default=time.time()))
post.file_last_modified_time = file_last_modified_time
def update_post_safety(post: model.Post, safety: str) -> None:
assert post
safety = util.flip(SAFETY_MAP).get(safety, None)

View file

@ -20,6 +20,7 @@ def upgrade():
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("user_id", sa.Integer(), nullable=True),
sa.Column("creation_time", sa.DateTime(), nullable=False),
sa.Column("file_last_modified_time", sa.DateTime(), nullable=False),
sa.Column("last_edit_time", sa.DateTime(), nullable=True),
sa.Column("safety", sa.Unicode(length=32), nullable=False),
sa.Column("type", sa.Unicode(length=32), nullable=False),

View file

@ -210,6 +210,7 @@ class Post(Base):
version = sa.Column("version", sa.Integer, default=1, nullable=False)
creation_time = sa.Column("creation_time", sa.DateTime, nullable=False)
last_edit_time = sa.Column("last_edit_time", sa.DateTime)
file_last_modified_time = sa.Column("file_last_modified_time", sa.DateTime, nullable=False)
safety = sa.Column("safety", sa.Unicode(32), nullable=False)
source = sa.Column("source", sa.Unicode(2048))
flags_string = sa.Column("flags", sa.Unicode(32), default="")