-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from evinjaff/dockerized-http-pkhex
Dockerized http pkhex (in progress)
- Loading branch information
Showing
12 changed files
with
206 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Test pkhex Docker Building | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
|
||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build the Docker image | ||
run: docker build . --file dockerfile --tag my-image-name:$(date +%s) | ||
working-directory: ./pkhex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
docker build -t pkhex . | ||
|
||
docker run -d -it -p 8000:8000 pkhex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM ubuntu:22.04 AS builder | ||
|
||
# install the .NET 8 SDK | ||
RUN apt-get update && apt-get install -y dotnet-sdk-8.0 ca-certificates | ||
|
||
# add your application code | ||
WORKDIR /source | ||
|
||
# copy pkhex-egglocke folder to the container | ||
COPY pkhex-egglocke . | ||
|
||
|
||
# Install pkhex dependency | ||
RUN dotnet restore pkhex-egglocke | ||
|
||
# Compile the app to test | ||
RUN dotnet build --no-restore pkhex-egglocke | ||
|
||
# Publish | ||
RUN dotnet publish -c release -r linux-x64 --self-contained | ||
|
||
|
||
ENV PORT 1234 | ||
EXPOSE 1234 | ||
|
||
WORKDIR /source/pkhex-egglocke | ||
ENTRYPOINT ["dotnet", "run"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace pkhex_egglocke | ||
{ | ||
public class SaveFileGeneratorModel | ||
{ | ||
public int generation { get; set; } = 4; | ||
public string jsonRaw { get; set; } = ""; | ||
public dynamic[] eggs { get; set; } =Array.Empty<dynamic>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Grapevine; | ||
using Newtonsoft.Json; | ||
using PKHeX.Core; | ||
using pkhexEgglocke; | ||
|
||
namespace pkhex_egglocke | ||
{ | ||
[RestResource] | ||
public class MyResource: Resource | ||
{ | ||
[RestRoute("Get", "/api/test")] | ||
public async Task Test(IHttpContext context) | ||
{ | ||
await context.Response.SendResponseAsync("Successfully hit the test route!"); | ||
} | ||
|
||
[RestRoute("Get", "/api/startfile")] | ||
public async Task StartFile(IHttpContext context) | ||
{ | ||
await context.Response.SendResponseAsync("Successfully hit the startfile route!"); | ||
} | ||
|
||
[RestRoute("Get", "/api/file1")] | ||
public async Task DownloadFile(IHttpContext context) | ||
{ | ||
string filePath = "C:\\Users\\Evin Jaff\\Downloads\\Pokemon.mp3"; | ||
|
||
context.Response.ContentType = "audio/mpeg"; | ||
context.Response.AddHeader("Content-Disposition", "attachment; filename=blank.mp3"); | ||
context.Response.ContentLength64 = new FileInfo(filePath).Length; | ||
|
||
await context.Response.SendResponseAsync(File.ReadAllBytes(filePath)); | ||
|
||
} | ||
|
||
[RestRoute("Post", "/api/buildSaveFile")] | ||
public async Task BuildSaveFile(IHttpContext context) | ||
{ | ||
// Decode the input stream | ||
var model = await DeserializeAsync<SaveFileGeneratorModel>(context.Request.InputStream, context.CancellationToken); | ||
|
||
// yields array of dynamic objects | ||
SaveWriter sw = new SaveWriter("C:\\Users\\Evin Jaff\\Downloads\\Blank_SoulSilver.sav"); | ||
|
||
EggCreator[] eggArray = new EggCreator[model.eggs.Length]; | ||
for (int i = 0; i < model.eggs.Length; i++) { | ||
EggCreator constructed_egg_creator = EggCreator.decodeJSON(model.eggs[i].ToString(), false); | ||
sw.addEgg(constructed_egg_creator, i+1); | ||
} | ||
|
||
byte[] saveFile = sw.exportRawBytes(); | ||
|
||
// Prepare the response as a downloadable file | ||
context.Response.ContentType = "application/octet-stream"; | ||
context.Response.AddHeader("Content-Disposition", "attachment; filename=blank.sav"); | ||
context.Response.ContentLength64 = saveFile.Length; | ||
|
||
await context.Response.SendResponseAsync(saveFile); | ||
|
||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
|
||
namespace pkhex_egglocke | ||
{ | ||
public abstract class Resource | ||
{ | ||
public static JsonSerializerOptions SerializerOptions = new JsonSerializerOptions() | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}; | ||
|
||
public async Task<T> DeserializeAsync<T>(Stream stream) | ||
{ | ||
return await DeserializeAsync<T>(stream, CancellationToken.None); | ||
} | ||
|
||
public async Task<T> DeserializeAsync<T>(Stream stream, CancellationToken token) | ||
{ | ||
return await JsonSerializer.DeserializeAsync<T>(stream, SerializerOptions, token); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters