|
4 | 4 | # When a user use an image from an external domain on LinuxFr.org, we keep some |
5 | 5 | # infos about this image in redis, so it can served by our proxy/cache daemon, img. |
6 | 6 | # |
7 | | -class Image < Struct.new(:link, :title, :alt_text) |
| 7 | +class Image < Struct.new(:link, :title, :alt_text, :blocked) |
8 | 8 | LATEST_KEY = "img/latest" |
9 | 9 | NB_IMG_IN_LATEST = 100 |
| 10 | + BLOCKED_KEY = "img/blocked" |
10 | 11 | E403 = "/images/403.png" |
11 | 12 |
|
12 | 13 | def self.latest(nb=NB_IMG_IN_LATEST) |
13 | 14 | links = $redis.lrange LATEST_KEY, 0, nb |
14 | | - links.map {|l| Image.new(l, l, l) } |
| 15 | + links.map {|l| Image.new(l, l, l, ($redis.hget "img/#{l}", "status") == "Blocked") } |
| 16 | + end |
| 17 | + |
| 18 | + def self.blocked(nb) |
| 19 | + links = $redis.lrange BLOCKED_KEY, 0, nb |
| 20 | + links.map {|l| Image.new(l, l, l, ($redis.hget "img/#{l}", "status") == "Blocked") } |
15 | 21 | end |
16 | 22 |
|
17 | 23 | def self.decoded_link(encoded_link) |
18 | 24 | [encoded_link].pack('H*') |
19 | 25 | end |
20 | 26 |
|
21 | 27 | def self.destroy(encoded_link) |
22 | | - $redis.hset "img/#{decoded_link encoded_link}", "status", "Blocked" |
| 28 | + link = decoded_link(encoded_link) |
| 29 | + if $redis.hset "img/#{link}", "status", "Blocked" |
| 30 | + $redis.lpush BLOCKED_KEY, link |
| 31 | + end |
23 | 32 | end |
24 | 33 |
|
25 | 34 | def self.original_link(link) |
|
0 commit comments