1 |
3 |
ahitrov@rambler.ru |
package Utils::ProxyImage; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use Digest::MD5 'md5_hex'; |
5 |
|
|
|
6 |
|
|
sub get_uri { |
7 |
|
|
my $url = shift; |
8 |
|
|
my $state = shift; |
9 |
|
|
my $format = shift; |
10 |
|
|
|
11 |
|
|
return '/i/_.gif' unless $format; |
12 |
|
|
|
13 |
|
|
my $secret = $state->proxy_image_secret || 're2anteros'; |
14 |
|
|
|
15 |
|
|
if ($url =~ /^https?:\/\/(.*)/i) { |
16 |
|
|
$url = $1; |
17 |
|
|
} else { |
18 |
|
|
return '/i/_.gif'; |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
$url =~ s/\/+/\//g; |
22 |
|
|
|
23 |
|
|
my $hash = md5_hex($url.$secret); |
24 |
|
|
|
25 |
|
|
$url = '/'.$format.'/'.$hash.'/'.$url; |
26 |
|
|
return $state->httpd_root.$state->proxy_image_location.$url; |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
1; |
30 |
|
|
|
31 |
|
|
__DATA__ |
32 |
|
|
|
33 |
|
|
������� ��� ������������ URI �������� ����� proxy image |
34 |
|
|
|
35 |
|
|
��� ������ ������ ���� ������ �������������� location � ngnix, ������� ��������� �� ������������ ������� �������� |
36 |
|
|
�������� ���: |
37 |
|
|
|
38 |
|
|
location /proxy-image/ { |
39 |
|
|
proxy_pass http://imgproxy_upstream/; |
40 |
|
|
proxy_set_header Host i1.rambler.ru; |
41 |
|
|
proxy_cache cache; |
42 |
|
|
proxy_cache_valid 24h; |
43 |
|
|
proxy_cache_use_stale error timeout; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
!!!�����!!! �� ����� � location ���������� � ������, ������ �� ���������� ���������� $format ��� ������ ������ |
47 |
|
|
|
48 |
|
|
� config.mk ������� �������� 2 ����� ����������: |
49 |
|
|
|
50 |
|
|
PROXY_IMAGE_LOCATION = [���������� ��� location] |
51 |
|
|
PROXY_IMAGE_SECRET = [��������� ����� ��� ������������ md5] |
52 |
|
|
|
53 |
|
|
�������� ���: |
54 |
|
|
|
55 |
|
|
use Utils::ProxyImage; |
56 |
|
|
|
57 |
|
|
my $proxy_uri = Utils::ProxyImage::get_uri($url, $state, $format); |
58 |
|
|
|
59 |
|
|
���: |
60 |
|
|
$uri - ������ uri ��������; |
61 |
|
|
$state - $state Contenido |
62 |
|
|
$format - ������, �������. e.q. 'c70x70' |