public AssetMetadata GetMetadata(string id) { // Cache check if (m_Cache != null) { AssetBase asset = m_Cache.Get(id); if (asset != null) return asset.Metadata; } AssetMetadata metadata = null; Uri assetMetadataUri = GetAssetUri(id, "metadata"); // Remote metadata request CapsClient request = new CapsClient(assetMetadataUri); OSDMap responseMap = request.GetResponse(REQUEST_TIMEOUT) as OSDMap; if (responseMap != null) { // Parse the response GetAssetMetadataMessage message = new GetAssetMetadataMessage(); message.Deserialize(responseMap); metadata = new AssetMetadata(); metadata.ContentType = message.Metadata.ContentType; metadata.CreationDate = message.Metadata.CreationDate; metadata.Description = message.Metadata.Description; metadata.FullID = message.Metadata.ID; metadata.ID = id; metadata.Local = false; metadata.Name = message.Metadata.Name; metadata.SHA1 = Utils.EmptyBytes; //message.Metadata.SHA256; // FIXME: :-( metadata.Temporary = message.Metadata.Temporary; metadata.Type = (sbyte)CableBeachUtils.ContentTypeToSLAssetType(message.Metadata.ContentType); } else { m_log.Debug("[CABLE BEACH ASSETS]: Failed to fetch asset metadata from " + assetMetadataUri); } return metadata; }
public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { byte[] result = OpenMetaverse.Utils.EmptyBytes; httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "application/octet-stream"; string[] p = SplitParams(path); if (p.Length > 1) { if (p[p.Length - 1] == "data") { // Fetch the asset data from the database byte[] assetData = m_AssetService.GetData(p[p.Length - 2]); if (result != null) { httpResponse.StatusCode = (int)HttpStatusCode.OK; result = assetData; } } else if (p[p.Length - 1] == "metadata") { AssetMetadata metadata = m_AssetService.GetMetadata(p[p.Length - 2]); if (metadata != null) { GetAssetMetadataMessage message = new GetAssetMetadataMessage(); message.Metadata = new MetadataDefault(); message.Metadata.ContentType = CableBeachUtils.SLAssetTypeToContentType(metadata.Type); message.Metadata.CreationDate = metadata.CreationDate; message.Metadata.Description = metadata.Description; UUID.TryParse(metadata.ID, out message.Metadata.ID); message.Metadata.Methods = new System.Collections.Generic.Dictionary<string, Uri>(0); message.Metadata.Name = metadata.Name; message.Metadata.SHA256 = OpenMetaverse.Utils.EmptyBytes; // TODO: metadata.SHA1; message.Metadata.Temporary = metadata.Temporary; httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = "application/json"; httpResponse.ContentEncoding = Encoding.UTF8; result = Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(message.Serialize())); } } else { // TODO: Send the metadata and data back together } } return result; }