Mercurial Hosting > linkmystyle
comparison src/init.luan @ 0:8f4df159f06b
start public repo
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 11 Jul 2025 20:57:49 -0600 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:8f4df159f06b |
|---|---|
| 1 local Luan = require "luan:Luan.luan" | |
| 2 local error = Luan.error | |
| 3 local String = require "luan:String.luan" | |
| 4 local substring = String.sub or error() | |
| 5 local regex = String.regex or error() | |
| 6 local contains = String.contains or error() | |
| 7 local Table = require "luan:Table.luan" | |
| 8 local concat = Table.concat or error() | |
| 9 local Time = require "luan:Time.luan" | |
| 10 local Thread = require "luan:Thread.luan" | |
| 11 local Http = require "luan:http/Http.luan" | |
| 12 local Hosted = require "luan:host/Hosted.luan" | |
| 13 local User = require "site:/lib/User.luan" | |
| 14 local get_user_by_name = User.get_by_name or error() | |
| 15 local name_regex = User.name_regex | |
| 16 local main_html = require "site:/lib/main_html.luan" | |
| 17 local Logging = require "luan:logging/Logging.luan" | |
| 18 local logger = Logging.logger "init" | |
| 19 | |
| 20 | |
| 21 Hosted.set_https and Hosted.set_https(true) | |
| 22 | |
| 23 local bad_bots = { | |
| 24 [[facebookexternalhit]] | |
| 25 [[VivoBrowser]] | |
| 26 [[\QFirefox/3.\E]] | |
| 27 [[\QFirefox/50.\E]] | |
| 28 [[SemrushBot]] | |
| 29 [[LightspeedSystemsCrawler]] | |
| 30 [[bingbot]] | |
| 31 [[PetalBot]] | |
| 32 [[\QChrome/83.\E]] | |
| 33 } | |
| 34 local bad_bots_ptn = regex(concat(bad_bots,"|")) | |
| 35 | |
| 36 function Http.error_priority(e) | |
| 37 local request = Http.request or error() | |
| 38 local agent = request.headers["user-agent"] | |
| 39 local referrer = request.headers.referer | |
| 40 if agent~=nil and bad_bots_ptn.matches(agent) then return "info" end | |
| 41 if e.priority ~= nil then return e.priority end | |
| 42 if referrer==nil or contains(referrer,"baidu.com") or contains(referrer,"google.com") then return "warn" end | |
| 43 return "error" | |
| 44 end | |
| 45 | |
| 46 function Http.not_found_handler() | |
| 47 local s = substring(Http.request.path,2) | |
| 48 --logger.info(s) | |
| 49 if not name_regex.matches(s) then | |
| 50 return false | |
| 51 end | |
| 52 local user = get_user_by_name(s) | |
| 53 if user == nil then | |
| 54 return false | |
| 55 end | |
| 56 main_html(user) | |
| 57 return true | |
| 58 end | |
| 59 | |
| 60 logger.error "init" | |
| 61 local function log_day() | |
| 62 logger.error("day") | |
| 63 end | |
| 64 Thread.schedule( log_day, { repeating_delay=Time.period{days=1} } ) | |
| 65 | |
| 66 local Uploadcare = require "site:/lib/Uploadcare.luan" | |
| 67 Thread.schedule( Uploadcare.gc, { repeating_delay=Time.period{days=1} } ) | |
| 68 | |
| 69 return true |
