summaryrefslogtreecommitdiff
path: root/send.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-07-29 20:59:48 +0200
committerpdp8 <pdp8@pdp8.info>2023-07-29 20:59:48 +0200
commitc50f749a2685a3e7608cec8730f5fe79de4676ac (patch)
tree75192aac75c86a6593737b1bdeb211f0799a5a8e /send.rb
parent3daf30b0a3837d3d8becb0baceed580e92403ce6 (diff)
POST /create
Diffstat (limited to 'send.rb')
-rw-r--r--send.rb76
1 files changed, 0 insertions, 76 deletions
diff --git a/send.rb b/send.rb
deleted file mode 100644
index 6dd4f3b..0000000
--- a/send.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-post '/outbox' do # TODO
- protected!
-
- recipients = params[:public] == 'true' ? public : []
- recipients << params[:to]
-
- tag = []
- params[:content].lines.each do |line|
- tags = line.split(/\s+/).grep(/^#\w+$/)
- tags.each do |name|
- tag_url = File.join(TAGS[:url], name.sub('#', ''))
- tag << {
- 'type' => 'Hashtag',
- 'href' => tag_url,
- 'name' => name
- }
- end
-
- mentions = line.split(/\s+/).grep(/^@\w+@\S+$/)
- mentions.each do |mention|
- actor = actor(mention)
- tag << {
- 'type' => 'Mention',
- 'href' => actor,
- 'name' => mention
- }
- end
- end
-
- attachment = []
- extensions = {
- image: %w[jpeg png],
- audio: %w[flac wav mp3 ogg],
- video: %w[mp4 webm]
- }
- if params[:media]
- params[:media].each do |_media|
- ext = File.extname(line).sub('.', '')
- media_type = extensions.select { |_k, v| v.include? ext }.keys[0].to_s + '/' + ext
- attachment << {
- 'type' => 'Document',
- 'mediaType' => media_type,
- 'url' => line
- }
- end
- end
-
- object = {
- 'type' => 'Note',
- 'attributedTo' => ACTOR,
- 'inReplyTo' => params[:inReplyTo],
- 'content' => "<p>\n#{params[:content]}\n</p>",
- 'attachment' => attachment,
- 'tag' => tag,
- 'to' => recipients
- }
-
- activity = outbox 'Create', object, recipients
- activity['object']['tag'].each do |tag|
- next unless tag['type'] == 'Hashtag'
-
- tag_path = File.join(TAGS[:dir], tag['name'].sub('#', '')) + '.json'
- next if File.exist? tag_path
-
- File.open(tag_path, 'w+') do |f|
- tag_collection = {
- '@context' => 'https://www.w3.org/ns/activitystreams',
- 'id' => tag['href'],
- 'type' => 'OrderedCollection',
- 'totalItems' => 0,
- 'orderedItems' => []
- }
- f.puts tag_collection.to_json
- end
- end
-end