├── README.md ├── worknotes.md ├── package.json ├── LICENSE ├── getenclosureinfo.js └── source.opml /README.md: -------------------------------------------------------------------------------- 1 | # getEnclosureInfo 2 | 3 | Node app to get information about a data file necessary for including in an RSS enclosure element. 4 | 5 | -------------------------------------------------------------------------------- /worknotes.md: -------------------------------------------------------------------------------- 1 | 7/24/23; 9:23:30 AM by DW 2 | 3 | Replace the part of pub2.fargo.io that's still in use. 4 | 5 | Example of use: 6 | 7 | http://pub2.fargo.io:5347/getenclosureinfo?url=http://scripting.com/2023/07/24/mantonVoicemail.m4a 8 | 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "getenclosureinfo", 3 | "description": "Get information about a data file necessary for including in an RSS enclosure element.", 4 | "version": "0.4.0", 5 | "main": "getenclosureinfo.js", 6 | "dependencies" : { 7 | "daveutils": "*", 8 | "davehttp": "*", 9 | "request": "*" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Dave Winer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /getenclosureinfo.js: -------------------------------------------------------------------------------- 1 | const fs = require ("fs"); 2 | const request = require ("request"); 3 | const utils = require ("daveutils"); 4 | const davehttp = require ("davehttp"); 5 | 6 | const config = { 7 | port: 5347, 8 | flAllowAccessFromAnywhere: true, 9 | flLogToConsole: true 10 | }; 11 | 12 | function getEnclosureInfo (url, callback) { //7/24/23 by DW 13 | var options = { 14 | uri: url, 15 | method: "HEAD" 16 | }; 17 | request (options, function (err, response, body) { 18 | if (err) { 19 | callback (err); 20 | } 21 | else { 22 | if (response.statusCode == 200) { 23 | callback (undefined, { 24 | length: Number (response.headers ["content-length"]), 25 | type: response.headers ["content-type"] 26 | }); 27 | } 28 | else { 29 | const message = "Can't get the enclosure info because we received status code == " + response.statusCode + "."; 30 | callback ({message}); 31 | } 32 | } 33 | }); 34 | } 35 | 36 | davehttp.start (config, function (theRequest) { 37 | const params = theRequest.params; 38 | function returnPlainText (s) { 39 | theRequest.httpReturn (200, "text/plain", s.toString ()); 40 | } 41 | function returnNotFound () { 42 | theRequest.httpReturn (404, "text/plain", "Not found."); 43 | } 44 | function returnError (jstruct) { 45 | theRequest.httpReturn (500, "application/json", utils.jsonStringify (jstruct)); 46 | } 47 | function returnData (jstruct) { 48 | if (jstruct === undefined) { 49 | jstruct = {}; 50 | } 51 | theRequest.httpReturn (200, "application/json", utils.jsonStringify (jstruct)); 52 | } 53 | function httpReturn (err, jstruct) { 54 | if (err) { 55 | returnError (err); 56 | } 57 | else { 58 | returnData (jstruct); 59 | } 60 | } 61 | function returnJSONP (err, jstruct) { 62 | if (err) { 63 | returnError (err); 64 | } 65 | else { 66 | const jsonptext = "getData (" + JSON.stringify (jstruct) + ")"; 67 | theRequest.httpReturn (200, "application/javascript", jsonptext); 68 | } 69 | } 70 | switch (theRequest.lowerpath) { 71 | case "/getenclosureinfo": 72 | getEnclosureInfo (params.url, returnJSONP); 73 | return (true); 74 | case "/now": 75 | returnPlainText (new Date ()); 76 | return (true); 77 | default: 78 | returnNotFound (); 79 | return (true); 80 | } 81 | }); 82 | 83 | -------------------------------------------------------------------------------- /source.opml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 16 | 17 | nodeEditor: getEnclosureInfo 18 | Mon, 24 Jul 2023 13:52:32 GMT 19 | Tue, 25 Jul 2023 13:14:41 GMT 20 | Dave Winer 21 | http://davewiner.com/ 22 | 1, 4, 14, 16, 24, 26 23 | 2 24 | 184 25 | 1043 26 | 917 27 | 2015 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | --------------------------------------------------------------------------------