Index: trunk/extensions/SwiftMedia/wmf/rewrite.py |
— | — | @@ -167,18 +167,24 @@ |
168 | 168 | # example: |
169 | 169 | # http://upload.wikimedia.org/wikipedia/commons/a/aa/000_Finlanda_harta.PNG |
170 | 170 | # http://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/000_Finlanda_harta.PNG/75px-000_Finlanda_harta.PNG |
171 | | - match = re.match(r'/(.*?)/(.*?)/(.*)', req.path) |
| 171 | + match = re.match(r'/(?P<proj>.*?)/(?P<lang>.*?)/(?P<thumb>thumb/)?(?P<shard>./../)?(?P<path>.*)', req.path) |
172 | 172 | if match: |
173 | 173 | # Our target URL is as follows (example): |
174 | | - # https://alsted.wikimedia.org:8080/v1/AUTH_6790933748e741268babd69804c6298b/wikipedia-en/2/25/Machinesmith.png |
| 174 | + # https://alsted.wikimedia.org:8080/v1/AUTH_6790933748e741268babd69804c6298b/wikipedia-en-25/Machinesmith.png |
| 175 | + # http://msfe/v1/AUTH_6790933748e741268babd69804c6298b/wikipedia-commons-aa/000_Finlanda_harta.PNG |
| 176 | + # http://mfse/v1/AUTH_6790933748e741268babd69804c6298b/wikipedia-commons-thumb-aa/000_Finlanda_harta.PNG/75px-000_Finlanda_harta.PNG |
175 | 177 | |
176 | 178 | # quote slashes in the container name |
177 | | - container = "%s-%s" % (match.group(1), match.group(2)) #02 |
178 | | - obj = match.group(3) |
| 179 | + container = "%s-%s" % (match.group('proj'), match.group('lang')) #02 |
| 180 | + thumb = match.group('thumb') |
| 181 | + shard = match.group('shard') |
| 182 | + obj = match.group('path') |
179 | 183 | # include the thumb in the container. |
180 | | - if obj.startswith("thumb/"): #03 |
| 184 | + if thumb: #03 |
181 | 185 | container += "-thumb" |
182 | | - obj = obj[len("thumb/"):] |
| 186 | + if shard: |
| 187 | + #add only the 2-digit shard to the container name |
| 188 | + container += "-%s" % shard[2:4] |
183 | 189 | |
184 | 190 | if not obj: |
185 | 191 | # don't let them list the container (it's CRAZY huge) #08 |