From fa367a28f17cc09155ce847a6b1b13c6e2b6e529 Mon Sep 17 00:00:00 2001 From: Tangent Date: Wed, 17 Apr 2019 21:05:33 -0700 Subject: [PATCH] v1 running live --- .gitignore | 5 +++ app.moon | 33 +++++++++++++++++++ config.moon | 9 ++++++ migrations.moon | 12 +++++++ mime.types | 81 ++++++++++++++++++++++++++++++++++++++++++++++ models.moon | 2 ++ models/Tracks.moon | 11 +++++++ nginx.conf | 33 +++++++++++++++++++ views/index.moon | 61 ++++++++++++++++++++++++++++++++++ 9 files changed, 247 insertions(+) create mode 100644 .gitignore create mode 100644 app.moon create mode 100644 config.moon create mode 100644 migrations.moon create mode 100644 mime.types create mode 100644 models.moon create mode 100644 models/Tracks.moon create mode 100644 nginx.conf create mode 100644 views/index.moon diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..77879d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.lua +*_temp/ +logs/ +import/ +nginx.conf.compiled diff --git a/app.moon b/app.moon new file mode 100644 index 0000000..b9e3790 --- /dev/null +++ b/app.moon @@ -0,0 +1,33 @@ +lapis = require "lapis" +console = require "lapis.console" + +import respond_to from require "lapis.application" +import Tracks from require "models" + +class extends lapis.Application + "/console": console.make! + + [index: "/(:page[%d])"]: respond_to { + GET: => + tracks = Tracks\paginated "* ORDER BY id", per_page: 32 + @page = tonumber(@params.page) or 1 + @tracks = tracks\get_page @page + render: true + POST: => + if @params.id + track = Tracks\find id: @params.id + track\update { + artist: @params.artist + name: @params.name + url: @params.url + status: tonumber @params.status + } + else + Tracks\create { + artist: @params.artist + name: @params.name + url: @params.url + status: @params.status + } + redirect_to: @url_for "index", page: @params.page + } diff --git a/config.moon b/config.moon new file mode 100644 index 0000000..ce8048e --- /dev/null +++ b/config.moon @@ -0,0 +1,9 @@ +import config from require "lapis.config" + +config "development", -> + port 8042 + postgres -> + host "127.0.0.1" + user "music" + password "EditAnacronTango" + database "music" diff --git a/migrations.moon b/migrations.moon new file mode 100644 index 0000000..1a03221 --- /dev/null +++ b/migrations.moon @@ -0,0 +1,12 @@ +import create_table, types from require "lapis.db.schema" + +{ + [1]: => + create_table "tracks", { + { "id", types.serial primary_key: true } + { "artist", types.text null: true } + { "name", types.text null: true } + { "url", types.text null: true } + { "status", types.integer default: 1 } + } +} diff --git a/mime.types b/mime.types new file mode 100644 index 0000000..292f886 --- /dev/null +++ b/mime.types @@ -0,0 +1,81 @@ +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/x-lua lua; + application/x-moonscript moon; + application/x-javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/png png; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + image/svg+xml svg svgz; + image/webp webp; + + application/java-archive jar war ear; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.ms-excel xls; + application/vnd.ms-powerpoint ppt; + application/vnd.wap.wmlc wmlc; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream eot; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/models.moon b/models.moon new file mode 100644 index 0000000..70be8f2 --- /dev/null +++ b/models.moon @@ -0,0 +1,2 @@ +import autoload from require "lapis.util" +autoload "models" diff --git a/models/Tracks.moon b/models/Tracks.moon new file mode 100644 index 0000000..5c7af1b --- /dev/null +++ b/models/Tracks.moon @@ -0,0 +1,11 @@ +import Model, enum from require "lapis.db.model" + +class Tracks extends Model + @statuses: enum { + new: 1 + downloaded: 2 + owned: 3 + duplicate: 4 + ignored: 5 + imported: 6 + } diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..465726a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,33 @@ +worker_processes ${{NUM_WORKERS}}; +error_log stderr notice; +daemon off; +pid logs/nginx.pid; + +events { + worker_connections 1024; +} + +http { + charset UTF-8; + include mime.types; + + server { + listen ${{PORT}}; + lua_code_cache ${{CODE_CACHE}}; + + location / { + default_type text/html; + content_by_lua ' + require("lapis").serve("app") + '; + } + + location /static/ { + alias static/; + } + + location /favicon.ico { + alias static/favicon.ico; + } + } +} diff --git a/views/index.moon b/views/index.moon new file mode 100644 index 0000000..1489c1e --- /dev/null +++ b/views/index.moon @@ -0,0 +1,61 @@ +import Widget from require "lapis.html" + +import Tracks from require "models" + +class extends Widget + content: => + div -> + a href: @url_for("index", page: @page - 1), "<" + raw " " + a href: @url_for("index", page: @page + 1), ">" + element "table", -> + tr -> + th "Artist" + th "Name" + th "URL" + th "Status" + th "✓" + + for track in *@tracks + tr -> + form { + action: @url_for "index", page: @page + method: "POST" + enctype: "multipart/form-data" + }, -> + td -> input type: "text", name: "artist", value: track.artist + td -> input type: "text", name: "name", value: track.name + td -> + if track.url and #track.url > 0 + a href: track.url, "*" + else + text "+" + text " " + input type: "text", name: "url", value: track.url + td -> + element "select", name: "status", -> + for status in *Tracks.statuses + if status == Tracks.statuses[track.status] + option value: Tracks.statuses[status], selected: true, status + else + option value: Tracks.statuses[status], status + td -> + input type: "hidden", name: "id", value: track.id + input type: "submit", value: "Update" + + tr -> + form { + action: @url_for "index", page: @page + method: "POST" + enctype: "multipart/form-data" + }, -> + td -> input type: "text", name: "artist", placeholder: "artist" + td -> input type: "text", name: "name", placeholder: "name" + td -> + raw "   " + input type: "text", name: "url", placeholder: "url" + td -> + element "select", name: "status", -> + for status in *Tracks.statuses + option value: Tracks.statuses[status], status + td -> input type: "submit", value: "Submit"