| 54 |
path = Path.Combine(UPLOAD_DATA_DIR, filename); |
path = Path.Combine(UPLOAD_DATA_DIR, filename); |
| 55 |
} |
} |
| 56 |
|
|
| 57 |
|
public static bool TryGetAssetData(UUID assetID, out AssetData assetData) |
| 58 |
|
{ |
| 59 |
|
return metadataStorage.TryGetValue(assetID, out assetData); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
public static bool TryGetMetadata(UUID assetID, out LLSD metadata) |
public static bool TryGetMetadata(UUID assetID, out LLSD metadata) |
| 63 |
{ |
{ |
| 64 |
// FIXME: Generate the LLSD at startup instead of on the fly |
// FIXME: Generate the LLSD at startup instead of on the fly |
| 243 |
|
|
| 244 |
public void FetchData(UUID assetID, HttpListenerContext context) |
public void FetchData(UUID assetID, HttpListenerContext context) |
| 245 |
{ |
{ |
| 246 |
|
AssetData assetData; |
| 247 |
|
if (SimpleDataStorage.TryGetAssetData(assetID, out assetData)) |
| 248 |
|
{ |
| 249 |
|
try |
| 250 |
|
{ |
| 251 |
|
Stream fileStream = new FileStream(assetData.Filename, FileMode.Open, FileAccess.Read, FileShare.Read); |
| 252 |
|
int dataToRead = (int)fileStream.Length; |
| 253 |
|
|
| 254 |
|
string extension = assetData.Asset.AssetType.ToString().ToLower(); |
| 255 |
|
|
| 256 |
|
context.Response.StatusCode = (int)HttpStatusCode.OK; |
| 257 |
|
switch (assetData.Asset.AssetType) |
| 258 |
|
{ |
| 259 |
|
case AssetType.Texture: |
| 260 |
|
// RFC 3745 |
| 261 |
|
context.Response.ContentType = "image/jp2"; |
| 262 |
|
extension = "j2c"; |
| 263 |
|
break; |
| 264 |
|
case AssetType.Sound: |
| 265 |
|
// RFC 3534 |
| 266 |
|
context.Response.ContentType = "audio/ogg"; |
| 267 |
|
extension = "ogg"; |
| 268 |
|
break; |
| 269 |
|
default: |
| 270 |
|
context.Response.ContentType = "application/octet-stream"; |
| 271 |
|
break; |
| 272 |
|
} |
| 273 |
|
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + |
| 274 |
|
String.Format("{0}.{1}", assetID, extension)); |
| 275 |
|
|
| 276 |
|
context.Response.ContentLength64 = dataToRead; |
| 277 |
|
|
| 278 |
|
// Stream the file |
| 279 |
|
byte[] buffer = new byte[2048]; |
| 280 |
|
|
| 281 |
|
while (dataToRead > 0) |
| 282 |
|
{ |
| 283 |
|
// Read the data in buffer |
| 284 |
|
int length = fileStream.Read(buffer, 0, 2048); |
| 285 |
|
|
| 286 |
|
// Write the data to the output stream |
| 287 |
|
context.Response.OutputStream.Write(buffer, 0, length); |
| 288 |
|
|
| 289 |
|
dataToRead -= length; |
| 290 |
|
} |
| 291 |
|
} |
| 292 |
|
catch (Exception ex) |
| 293 |
|
{ |
| 294 |
|
Logger.Log(String.Format("Failed sending data for asset {0} from {1}", assetID, assetData.Filename), |
| 295 |
|
Helpers.LogLevel.Error); |
| 296 |
|
|
| 297 |
|
try |
| 298 |
|
{ |
| 299 |
|
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; |
| 300 |
|
context.Response.StatusDescription = ex.Message; |
| 301 |
|
} |
| 302 |
|
catch (Exception) { } |
| 303 |
|
} |
| 304 |
|
} |
| 305 |
|
else |
| 306 |
|
{ |
| 307 |
|
context.Response.StatusCode = (int)HttpStatusCode.NotFound; |
| 308 |
|
} |
| 309 |
|
|
| 310 |
|
context.Response.Close(); |
| 311 |
} |
} |
| 312 |
} |
} |
| 313 |
|
|