Commit 75c493d4 authored by Bat's avatar Bat
Browse files

Posteing

parent 656c7f28
......@@ -48,6 +48,8 @@ Amber::Server.configure do |app|
get "/~:name", BlogController, :show
get "/~:name/new", BlogController, :new_post
post "/~:name/new", BlogController, :create_post
get "/~:name/:post", BlogController, :show_post
get "/blogs/new", BlogController, :new
post "/blogs", BlogController, :create
end
......
-- +micrate Up
ALTER TABLE posts ADD COLUMN blog_id BIGINT;
-- +micrate Down
ALTER TABLE posts DROP COLUMN blog_id;
......@@ -68,9 +68,54 @@
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
//import Amber from 'amber'
var Editor = function () {
function Editor(elt) {
_classCallCheck(this, Editor);
this.titleElt = elt.querySelector('h1');
this.elt = elt.querySelector('div');
this.csrf = elt.querySelector('input');
}
_createClass(Editor, [{
key: 'save',
value: function save() {
var data = new FormData();
data.append('title', this.titleElt.innerHTML);
data.append('content', this.elt.innerHTML);
data.append('_csrf', this.csrf.value);
fetch('', {
method: 'POST',
body: data,
credentials: 'include'
}).then(function (res) {
return res.json();
}).then(function (res) {
if (res.status === 'ok') {
window.location.href = res.url;
}
}).catch(function (err) {
console.log('Error : ', err);
});
}
}]);
return Editor;
}();
var ed = new Editor(document.getElementById('ed'));
document.getElementById('publish').addEventListener('click', function () {
ed.save();
});
/***/ })
/******/ ]);
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly8vd2Vic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ZmE0NjBlZjUyNWVmZTFkIiwiLy9pbXBvcnQgQW1iZXIgZnJvbSAnYW1iZXInXG5cbmNsYXNzIEVkaXRvciB7XG4gICAgY29uc3RydWN0b3IgKGVsdCkge1xuICAgICAgICB0aGlzLnRpdGxlRWx0ID0gZWx0LnF1ZXJ5U2VsZWN0b3IoJ2gxJylcbiAgICAgICAgdGhpcy5lbHQgPSBlbHQucXVlcnlTZWxlY3RvcignZGl2JylcbiAgICAgICAgdGhpcy5jc3JmID0gZWx0LnF1ZXJ5U2VsZWN0b3IoJ2lucHV0JylcbiAgICB9XG5cbiAgICBzYXZlICgpIHtcbiAgICAgICAgY29uc3QgZGF0YSA9IG5ldyBGb3JtRGF0YSgpXG4gICAgICAgIGRhdGEuYXBwZW5kKCd0aXRsZScsIHRoaXMudGl0bGVFbHQuaW5uZXJIVE1MKVxuICAgICAgICBkYXRhLmFwcGVuZCgnY29udGVudCcsIHRoaXMuZWx0LmlubmVySFRNTClcbiAgICAgICAgZGF0YS5hcHBlbmQoJ19jc3JmJywgdGhpcy5jc3JmLnZhbHVlKVxuICAgICAgICBmZXRjaCgnJywge1xuICAgICAgICAgICAgbWV0aG9kOiAnUE9TVCcsXG4gICAgICAgICAgICBib2R5OiBkYXRhLFxuICAgICAgICAgICAgY3JlZGVudGlhbHM6ICdpbmNsdWRlJ1xuICAgICAgICB9KS50aGVuKHJlcyA9PiB7XG4gICAgICAgICAgICByZXR1cm4gcmVzLmpzb24oKVxuICAgICAgICB9KS50aGVuKHJlcyA9PiB7XG4gICAgICAgICAgICBpZiAocmVzLnN0YXR1cyA9PT0gJ29rJykge1xuICAgICAgICAgICAgICAgIHdpbmRvdy5sb2NhdGlvbi5ocmVmID0gcmVzLnVybFxuICAgICAgICAgICAgfVxuICAgICAgICB9KS5jYXRjaChlcnIgPT4ge1xuICAgICAgICAgICAgY29uc29sZS5sb2coJ0Vycm9yIDogJywgZXJyKVxuICAgICAgICB9KVxuICAgIH1cbn1cblxuY29uc3QgZWQgPSBuZXcgRWRpdG9yKGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdlZCcpKVxuZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ3B1Ymxpc2gnKS5hZGRFdmVudExpc3RlbmVyKCdjbGljaycsICgpID0+IHtcbiAgICBlZC5zYXZlKClcbn0pXG5cblxuXG4vLyBXRUJQQUNLIEZPT1RFUiAvL1xuLy8gLi9zcmMvYXNzZXRzL2phdmFzY3JpcHRzL21haW4uanMiXSwic291cmNlUm9vdCI6IiJ9
\ No newline at end of file
//import Amber from 'amber'
class Editor {
constructor (elt) {
this.titleElt = elt.querySelector('h1')
this.elt = elt.querySelector('div')
this.csrf = elt.querySelector('input')
}
save () {
const data = new FormData()
data.append('title', this.titleElt.innerHTML)
data.append('content', this.elt.innerHTML)
data.append('_csrf', this.csrf.value)
fetch('', {
method: 'POST',
body: data,
credentials: 'include'
}).then(res => {
return res.json()
}).then(res => {
if (res.status === 'ok') {
window.location.href = res.url
}
}).catch(err => {
console.log('Error : ', err)
})
}
}
const ed = new Editor(document.getElementById('ed'))
document.getElementById('publish').addEventListener('click', () => {
ed.save()
})
......@@ -5,6 +5,14 @@ class ApplicationController < Amber::Controller::Base
LAYOUT = "application.ecr"
def get_account
begin
acct
rescue
nil
end
end
def acct
Repo.get(Account, session[:account_id].to_s.to_i).not_nil!
end
end
......@@ -2,7 +2,12 @@ class BlogController < ApplicationController
include ActivityPub::Utils
def get_blog
Blog.from_name(params["name"])
begin
Blog.from_name(params["name"])
rescue exception
halt!(404, "Not found")
Blog.new
end
end
def show
......@@ -31,4 +36,27 @@ class BlogController < ApplicationController
title = "New Post in " + get_blog.title.not_nil!
render("new_post.ecr")
end
def create_post
post = Post.new
post.title = params["title"]
post.content = params["content"]
id = Repo.insert(post).instance.id.to_s
respond_with {
json ({
"status" => "ok",
"url" => "/~" + get_blog.actor_id.not_nil! + "/" + id
}).to_json
}
end
def show_post
post = Repo.all(Post, Query
#.where(blog_id: get_blog.id.not_nil!)
.where(id: params["post"].to_s.to_i)
.limit(1)
)[0]
title = post.title
render("show_post.ecr")
end
end
......@@ -12,7 +12,7 @@ class Account < Crecto::Model
field :display_name, String
field :bio, String
has_one :personal_blog, Blog
has_many :posts, Post, dependent: :destroy
has_many :posts, Post, dependent: :destroy, foreign_key: :author_id
belongs_to :instance, Instance
end
......
......@@ -7,6 +7,7 @@ class Blog < Crecto::Model
field :default_license, String
belongs_to :instance, Instance
belongs_to :account, Account
has_many :posts, Post
end
def self.from_name (name : String)
......
......@@ -2,7 +2,8 @@ class Post < Crecto::Model
schema "posts" do
field :title, String
field :illustration, String
belongs_to :author, Account
belongs_to :author, Account, foreign_key: :author_id
belongs_to :blog, Blog
field :content, String
field :published, Bool
end
......
<main>
<main id="ed">
<%= csrf_tag %>
<h1 contenteditable>My post</h1>
<div contenteditable>
</div>
</main>
<button id="publish">Publish</button>
<h1><%= title %></h1>
<div>
<%= post.content %>
</div>
<footer>
In <%= get_blog.title %>
</footer>
<h1><%= instance.name %></h1>
<% if get_account != nil %>
<p>Welcome <%= get_account.display_name %>!</p>
<p>Welcome <%= acct.display_name %>!</p>
<% end %>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment