fixed a bunch of tag shenanigans

This commit is contained in:
Tangent 2019-06-28 17:55:21 -07:00
parent be734d28b1
commit 1fda7ef7fe
3 changed files with 10 additions and 8 deletions

View File

@ -3,8 +3,8 @@ console = require "lapis.console"
import respond_to from require "lapis.application"
import escape_literal, escape_identifier from require "lapis.db"
import unescape from require "lapis.util"
import create_track, update_track, escape_tag from require "helpers"
import escape, unescape from require "lapis.util"
import create_track, update_track from require "helpers"
import Tracks, Tags from require "models"
@ -52,6 +52,7 @@ class extends lapis.Application
return render: true
[tag: "/tag/:name(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
update_track(@params) if @params.id -- update a track if needed
-- validate order
@order = tostring(@params.order)\lower!
unless Tags.fields[@order]
@ -62,8 +63,13 @@ class extends lapis.Application
@asc_desc = "ASC"
@page = tonumber(@params.page) or 1
tag_pattern = escape_literal unescape(@params.name)
-- create tag pattern
tag_pattern = unescape(@params.name)
if tag_pattern != tag_pattern\lower!
return redirect_to: @url_for "tag", name: escape(tag_pattern\lower!), order: @order, asc_desc: @asc_desc, page: @page
tag_pattern = escape_literal tag_pattern
tag_pattern = "'% " .. tag_pattern\sub(2, -2) .. " %'"
tracks = Tracks\paginated "WHERE tags LIKE #{tag_pattern} ORDER BY #{escape_identifier @order} #{@asc_desc}", per_page: 32
@last_page = 1
if tag = Tags\find name: unescape(@params.name)

View File

@ -14,9 +14,6 @@ process_tags = (tags_str) ->
table.sort taglist
return " #{table.concat taglist, " "} "
escape_tag = (str) ->
return " #{str\gsub "[%%_]", "\\%1"} "
update_track = (user_input) ->
updates = {}
-- automatic tags
@ -49,7 +46,6 @@ update_track = (user_input) ->
return {
:process_tags
:escape_tag
:update_track
create_track: update_track
}

View File

@ -44,7 +44,7 @@ class extends Widget
for track in *@tracks
tr class: Tracks.statuses[track.status], ->
form {
action: @url_for "tracks", order: @order, asc_desc: @asc_desc, page: @page
action: @url_for "tag", name: @params.name, order: @order, asc_desc: @asc_desc, page: @page
method: "POST"
enctype: "multipart/form-data"
}, ->