@@ -56,7 +56,7 @@ func main() {
56
56
Flags : []cli.Flag {
57
57
cli.BoolFlag {
58
58
Name : "tor, t" ,
59
- Usage : "Post to Tor hidden service" ,
59
+ Usage : "Post via Tor hidden service" ,
60
60
},
61
61
cli.IntFlag {
62
62
Name : "tor-port" ,
@@ -72,7 +72,23 @@ func main() {
72
72
Flags : []cli.Flag {
73
73
cli.BoolFlag {
74
74
Name : "tor, t" ,
75
- Usage : "Delete from Tor hidden service" ,
75
+ Usage : "Delete via Tor hidden service" ,
76
+ },
77
+ cli.IntFlag {
78
+ Name : "tor-port" ,
79
+ Usage : "Use a different port to connect to Tor" ,
80
+ Value : 9150 ,
81
+ },
82
+ },
83
+ },
84
+ {
85
+ Name : "update" ,
86
+ Usage : "Update (overwrite) a post" ,
87
+ Action : cmdUpdate ,
88
+ Flags : []cli.Flag {
89
+ cli.BoolFlag {
90
+ Name : "tor, t" ,
91
+ Usage : "Update via Tor hidden service" ,
76
92
},
77
93
cli.IntFlag {
78
94
Name : "tor-port" ,
@@ -207,6 +223,35 @@ func cmdDelete(c *cli.Context) {
207
223
DoDelete (friendlyId , token , tor )
208
224
}
209
225
226
+ func cmdUpdate (c * cli.Context ) {
227
+ friendlyId := c .Args ().Get (0 )
228
+ token := c .Args ().Get (1 )
229
+ if friendlyId == "" {
230
+ fmt .Println ("usage: writeas update <postId> [<token>]" )
231
+ os .Exit (1 )
232
+ }
233
+
234
+ if token == "" {
235
+ // Search for the token locally
236
+ token = tokenFromID (friendlyId )
237
+ if token == "" {
238
+ fmt .Println ("Couldn't find an edit token locally. Did you create this post here?" )
239
+ fmt .Printf ("If you have an edit token, use: writeas update %s <token>\n " , friendlyId )
240
+ os .Exit (1 )
241
+ }
242
+ }
243
+
244
+ // Read post body
245
+ fullPost := readStdIn ()
246
+
247
+ tor := c .Bool ("tor" ) || c .Bool ("t" )
248
+ if c .Int ("tor-port" ) != 0 {
249
+ torPort = c .Int ("tor-port" )
250
+ }
251
+
252
+ DoUpdate (fullPost , friendlyId , token , tor )
253
+ }
254
+
210
255
func cmdGet (c * cli.Context ) {
211
256
friendlyId := c .Args ().Get (0 )
212
257
if friendlyId == "" {
@@ -310,6 +355,7 @@ func DoPost(post []byte, encrypt, tor bool) {
310
355
if encrypt {
311
356
data .Add ("e" , "" )
312
357
}
358
+ data .Add ("font" , "mono" )
313
359
314
360
urlStr , client := client (false , tor , "" , "" )
315
361
@@ -339,6 +385,35 @@ func DoPost(post []byte, encrypt, tor bool) {
339
385
}
340
386
}
341
387
388
+ func DoUpdate (post []byte , friendlyId , token string , tor bool ) {
389
+ urlStr , client := client (false , tor , "" , fmt .Sprintf ("id=%s&t=%s" , friendlyId , token ))
390
+
391
+ data := url.Values {}
392
+ data .Set ("w" , string (post ))
393
+
394
+ r , _ := http .NewRequest ("POST" , urlStr , bytes .NewBufferString (data .Encode ()))
395
+ r .Header .Add ("Content-Type" , "application/x-www-form-urlencoded" )
396
+ r .Header .Add ("Content-Length" , strconv .Itoa (len (data .Encode ())))
397
+
398
+ resp , err := client .Do (r )
399
+ check (err )
400
+ defer resp .Body .Close ()
401
+
402
+ if resp .StatusCode == http .StatusOK {
403
+ if tor {
404
+ fmt .Println ("Post updated via hidden service." )
405
+ } else {
406
+ fmt .Println ("Post updated." )
407
+ }
408
+ } else {
409
+ if DEBUG {
410
+ fmt .Printf ("Problem updating: %s\n " , resp .Status )
411
+ } else {
412
+ fmt .Printf ("Post doesn't exist, or bad edit token given.\n " )
413
+ }
414
+ }
415
+ }
416
+
342
417
func DoDelete (friendlyId , token string , tor bool ) {
343
418
urlStr , client := client (false , tor , "" , fmt .Sprintf ("id=%s&t=%s" , friendlyId , token ))
344
419
0 commit comments