Skip to content

Instantly share code, notes, and snippets.

@LeftofZen
Last active August 13, 2022 15:35
Show Gist options
  • Save LeftofZen/6e1c9a09dac51ae7141b2ec6d04afec3 to your computer and use it in GitHub Desktop.
Save LeftofZen/6e1c9a09dac51ae7141b2ec6d04afec3 to your computer and use it in GitHub Desktop.
A simple file server in asp.net 6 that servers openloco obj files in base64 encoding
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapGet("/object/{obj}", (string obj) =>
{
const string objFolderPath = @"Q:\Games\Locomotion\Objects";
var objFilename = Path.Combine(objFolderPath, $"{obj}.dat");
if (File.Exists(objFilename))
{
var bytes = File.ReadAllBytes(objFilename);
return System.Convert.ToBase64String(bytes);
}
return null;
});
app.Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment