67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
using System.IO;
|
|
using System.Web;
|
|
//using System.Web.Helpers;
|
|
using System.Web.Hosting;
|
|
using System.Net.Http.Headers;
|
|
using System.Threading.Tasks;
|
|
//using System.Web.Mvc;
|
|
|
|
|
|
[Route("files")]
|
|
public class FilesController : ApiController
|
|
{
|
|
// GET api/<controller>
|
|
public IEnumerable<string> Get()
|
|
{
|
|
return new string[] { "value1", "value2" };
|
|
}
|
|
|
|
[Route("upload/{*url}")]
|
|
public async Task<HttpResponseMessage> get_upload(string url)
|
|
{
|
|
var path = Sites.get_url("upload", url);
|
|
if (!System.IO.File.Exists(path))
|
|
{
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
}
|
|
string mimeType = MimeMapping.GetMimeMapping(path);
|
|
|
|
HttpResponseMessage response = new HttpResponseMessage();
|
|
response.Content = new StreamContent(new FileStream(path, FileMode.Open));
|
|
response.Content.Headers.ContentType = new MediaTypeHeaderValue(mimeType);
|
|
response.Headers.CacheControl = new CacheControlHeaderValue()
|
|
{
|
|
Public = true,
|
|
MaxAge = TimeSpan.FromSeconds(Sites.MaxAge)
|
|
};
|
|
|
|
return response;
|
|
}
|
|
[Route("public/{*url}")]
|
|
public string get_public (string url)
|
|
{
|
|
return "public:" + url;
|
|
}
|
|
|
|
// POST api/<controller>
|
|
public void Post([FromBody] string value)
|
|
{
|
|
}
|
|
|
|
// PUT api/<controller>/5
|
|
public void Put(int id, [FromBody] string value)
|
|
{
|
|
}
|
|
|
|
// DELETE api/<controller>/5
|
|
public void Delete(int id)
|
|
{
|
|
}
|
|
}
|