💾 Archived View for gemini.conman.org › extensions › port70 › handlers › blackhole.lua captured on 2021-12-03 at 14:04:38.

View Raw

More Information

⬅️ Previous capture (2020-10-31)

🚧 View Differences

-=-=-=-=-=-=-

-- ***********************************************************************
--
-- Module to prove a point about spidering gopherspace
-- Copyright 2019 by Sean Conner.
--
-- This program is free software: you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation, either version 3 of the License, or (at your
-- option) any later version.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
-- Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program.  If not, see <http://www.gnu.org/licenses/>.
--
-- Comments, questions and criticisms can be sent to: sean@conman.org
-- ***********************************************************************
-- luacheck: globals init handler
-- luacheck: ignore 611

local uuid     = require "org.conman.uuid"
local mklink   = require "port70.mklink"

local ipairs   = ipairs
local tostring = tostring

_ENV = {}

-- ************************************************************************

function init(conf)
  if not conf.prompt then
    return false,"missing prompt"
  end
  
  if not conf.verbiage then
    return false,"missing verbiage"
  end
  
  return true
end

-- ************************************************************************

function handler(conf,request,ios)
  for _,text in ipairs(conf.verbiage) do
    ios:write(mklink {type = 'info' , display = text })
  end
  
  -- ----------------------------------
  -- Try not to DoS ourselves here ...
  -- ----------------------------------
  
  local blob
  
  if #request.rest == 0 then
    blob = tostring(uuid())
  elseif #request.rest >= 16384 then
    blob = tostring(uuid())
  else
    blob = request.rest
  end
  
  ios:write(mklink {
        type     = 'dir',
        display  = conf.prompt,
        selector = request.selector .. request.rest .. tostring(uuid(uuid.URL,blob)),
  })
  
  return true
end

-- ************************************************************************

return _ENV