Browse Source

added image uploads

url input rather than file proper for now

clear your fltr_cache (`rm -r /tmp/fltr_cache`) for old posts to update with new :hover behaviour
Kyle Farwell 2 years ago
parent
commit
58aa83cd33
4 changed files with 87 additions and 7 deletions
  1. 22 0
      apps/dirdir/app.rc
  2. 15 4
      apps/dirdir/edit.tpl
  3. 7 2
      sites/tokumei.co/_werc/pub/style.css
  4. 43 1
      tpl/post.tpl

+ 22 - 0
apps/dirdir/app.rc

@@ -27,6 +27,28 @@ fn dirdir_init {
27 27
             }
28 28
         }
29 29
 
30
+        if(! ~ '' $"post_arg_file) {
31
+            if(~ $post_arg_file *.gif  ||
32
+               ~ $post_arg_file *.jpeg ||
33
+               ~ $post_arg_file *.jpg  ||
34
+               ~ $post_arg_file *.png  ||
35
+               ~ $post_arg_file *.ff   ||
36
+               ~ $post_arg_file *.tif  ||
37
+               ~ $post_arg_file *.tiff ||
38
+               ~ $post_arg_file *.bmp) {
39
+                file=`{basename $post_arg_file | sed 's/[^a-zA-Z0-9_.]//g'}
40
+                name=`{echo $file | sed 's/\.(gif|jpeg|jpg|png|ff|tif|tiff|bmp)$//'}
41
+                ext=`{echo $file | sed 's/.*\.(gif|jpeg|jpg|png|ff|tif|tiff|bmp)$/\1/'}
42
+
43
+                curl $post_arg_file > $postd/image.$ext
44
+
45
+                # make sure it's a real image
46
+                if(! convert $postd/image.$ext /tmp/tokumeiup.jpg ||
47
+                   ! convert $postd/image.$ext /tmp/tokumeiup.png)
48
+                    rm $postd/image.$ext
49
+            }
50
+        }
51
+
30 52
         if(! ~ '' $"post_arg_password) {
31 53
             salt=`{cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 64 | head -n 1}
32 54
             echo -n $post_arg_password$salt | sha256sum | sed 's/  -$//' > etc/passwords/$postn

+ 15 - 4
apps/dirdir/edit.tpl

@@ -9,7 +9,7 @@
9 9
 
10 10
       <div class="input-field">
11 11
         <input type="text" name="tags" id="tags">
12
-        <label for="tags">Tags (space separated)</label>
12
+        <label for="tags">Tags (comma separated)</label>
13 13
       </div>
14 14
 
15 15
       <!-- <div class="input-field file-field">
@@ -18,11 +18,16 @@
18 18
           <input type="file">
19 19
         </div>
20 20
         <div class="file-path-wrapper">
21
-          <input class="file-path validate" type="text" placeholder="(optional)">
21
+          <input class="file-path validate" type="text">
22 22
         </div>
23 23
       </div> -->
24 24
 
25 25
       <div class="input-field">
26
+        <input type="text" placeholder="https://example.com/image.png" name="file" id="file">
27
+        <label for="file">Attachment</label>
28
+      </div>
29
+
30
+      <div class="input-field">
26 31
         <input type="password" name="password" id="password">
27 32
         <label for="password">Deletion password</label>
28 33
       </div>
@@ -43,7 +48,7 @@
43 48
 
44 49
       <div class="input-field">
45 50
         <input type="text" name="tags" id="tags">
46
-        <label for="tags">Tags (space separated)</label>
51
+        <label for="tags">Tags (comma separated)</label>
47 52
       </div>
48 53
 
49 54
       <script>
@@ -65,10 +70,16 @@
65 70
             <input type="file">
66 71
           </div>
67 72
           <div class="file-path-wrapper">
68
-            <input class="file-path validate" type="text" placeholder="(optional)">
73
+            <input class="file-path validate" type="text">
69 74
           </div>
70 75
         </div> -->
71 76
 
77
+        <br /><br />
78
+        <div class="input-field">
79
+          <input type="text" placeholder="https://example.com/image.png" name="file" id="file">
80
+          <label for="file">Attachment</label>
81
+        </div>
82
+
72 83
         <div class="input-field">
73 84
           <input type="password" name="password" id="password">
74 85
           <label for="password">Deletion password</label>

+ 7 - 2
sites/tokumei.co/_werc/pub/style.css

@@ -280,10 +280,10 @@ blockquote {
280 280
 .card > a:hover {
281 281
   color: initial !important;
282 282
 }
283
-.card-content {
283
+.card-content.clicky {
284 284
   cursor: pointer;
285 285
 }
286
-.card-content:hover {
286
+.card-content.clicky:hover {
287 287
   background-color: rgba(0, 0, 0, 0.05);
288 288
 }
289 289
 
@@ -349,3 +349,8 @@ blockquote {
349 349
 .sitemap-list {
350 350
   padding-left: 2em;
351 351
 }
352
+
353
+.attachment {
354
+  width: 100%;
355
+  max-height: 80vh;
356
+}

+ 43 - 1
tpl/post.tpl

@@ -4,8 +4,22 @@
4 4
 % if(~ $req_path /p/[0-9]*) echo '<br />'
5 5
 % if(! test -f $postd/spam || ~ $req_path /p/[0-9]*) {
6 6
 <div class="card">
7
-  <div class="card-content" onclick="window.location='/p/%($postn%)'">
7
+%     if(~ $req_path /p/[0-9]*) {
8
+  <div class="card-content">
9
+%     }
10
+%     if not {
11
+  <div class="card-content clicky" onclick="window.location='/p/%($postn%)'">
12
+%     }
8 13
 %   sed $postfilter < $postf
14
+%     if(test -f $postd/image.*) {
15
+%         file=`{basename `{ls $postd/image.*}}
16
+%         if(~ $req_path /p/[0-9]*) {
17
+    <br /><a href="%($postn%)_werc/%($file%)"><img src="%($postn%)_werc/%($file%)" class="attachment" /></a>
18
+%         }
19
+%         if not {
20
+    <br /><a href="%($postn%)_werc/%($file%)">%($file%)</a>
21
+%         }
22
+%     }
9 23
   </div>
10 24
   <div class="card-action">
11 25
 
@@ -145,6 +159,10 @@
145 159
     <h5><a href="%($shareurl%)">%($shareurl%)</a></h5>
146 160
     <p class="break-word">
147 161
 %     sed $postfilter < $postf
162
+%     if(test -f $postd/image.*) {
163
+%         file=`{ls $postd/image.*}
164
+    <br /><a href="%($postd%)/%($file%)">%($file%)</a>
165
+%     }
148 166
     </p>
149 167
     <div class="collection">
150 168
       <a class="collection-item" href="http://twitter.com/home/?status=%($shareurl%)">
@@ -189,6 +207,10 @@
189 207
     <h5><a href="%($shareurl%)">%($shareurl%)</a></h5>
190 208
     <p class="break-word">
191 209
 %     sed $postfilter < $postf
210
+%     if(test -f $postd/image.*) {
211
+%         file=`{ls $postd/image.*}
212
+    <br /><a href="%($postd%)/%($file%)">%($file%)</a>
213
+%     }
192 214
     </p>
193 215
     <div class="collection">
194 216
       <a class="collection-item" href="http://twitter.com/home/?status=%($shareurl%)">
@@ -253,6 +275,10 @@
253 275
     <h5><a href="%($shareurl%)">%($shareurl%)</a></h5>
254 276
     <p class="break-word">
255 277
 %     sed $postfilter < $postf
278
+%     if(test -f $postd/image.*) {
279
+%         file=`{ls $postd/image.*}
280
+    <br /><a href="%($postd%)/%($file%)">%($file%)</a>
281
+%     }
256 282
     </p>
257 283
     <div class="collection">
258 284
       <form action="" method="post">
@@ -280,6 +306,10 @@
280 306
     <h5><a href="%($shareurl%)">%($shareurl%)</a></h5>
281 307
     <p class="break-word">
282 308
 %     sed $postfilter < $postf
309
+%     if(test -f $postd/image.*) {
310
+%         file=`{ls $postd/image.*}
311
+    <br /><a href="%($postd%)/%($file%)">%($file%)</a>
312
+%     }
283 313
     </p>
284 314
     <div class="collection">
285 315
       <form action="" method="post">
@@ -309,6 +339,10 @@
309 339
       <h5>If you wrote this post and set a password when you did, enter it below. If not, you're out of luck.</h5>
310 340
       <p class="break-word">
311 341
 %       sed $postfilter < $postf
342
+%     if(test -f $postd/image.*) {
343
+%         file=`{ls $postd/image.*}
344
+    <br /><a href="%($postd%)/%($file%)">%($file%)</a>
345
+%     }
312 346
       </p>
313 347
       <form action="" method="post">
314 348
         <input type="hidden" name="postn" value="%($postn%)">
@@ -328,6 +362,10 @@
328 362
       <h5>If you wrote this post and set a password when you did, enter it below. If not, you're out of luck.</h5>
329 363
       <p class="break-word">
330 364
 %       sed $postfilter < $postf
365
+%     if(test -f $postd/image.*) {
366
+%         file=`{ls $postd/image.*}
367
+    <br /><a href="%($postd%)/%($file%)">%($file%)</a>
368
+%     }
331 369
       </p>
332 370
       <br /><div class="input-field">
333 371
         <input type="password" name="delete" id="delete%($postn%)">
@@ -349,6 +387,10 @@
349 387
       <h5>If you wrote this post and set a password when you did, enter it below. If not, you're out of luck.</h5>
350 388
       <p class="break-word">
351 389
 %       sed $postfilter < $postf
390
+%     if(test -f $postd/image.*) {
391
+%         file=`{ls $postd/image.*}
392
+    <br /><a href="%($postd%)/%($file%)">%($file%)</a>
393
+%     }
352 394
       </p>
353 395
       <br /><div class="input-field">
354 396
         <input type="password" name="delete" id="delete%($postn%)">