-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch CORS GitHub problem release (#129)
- Loading branch information
Showing
9 changed files
with
115 additions
and
32 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
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,58 @@ | ||
package fr.zelytra.github; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
|
||
public class GithubApi { | ||
|
||
private static final String releaseUrl = "https://github.com/zelytra/BetterFleet/releases/latest/download/latest.json"; | ||
|
||
private final GithubRelease githubRelease; | ||
|
||
public GithubApi() throws IOException { | ||
// Create a neat value object to hold the URL | ||
URL url = new URL("https://github.com/zelytra/BetterFleet/releases/latest/download/latest.json"); | ||
|
||
// Open a connection(?) on the URL(??) and cast the response(???) | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
|
||
// Now it's "open", we can set the request method, headers etc. | ||
connection.setRequestProperty("Content-Type", "application/json"); | ||
connection.setRequestMethod("GET"); | ||
|
||
// This line makes the request | ||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
String inputLine; | ||
StringBuffer content = new StringBuffer(); | ||
while ((inputLine = in.readLine()) != null) { | ||
content.append(inputLine); | ||
} | ||
|
||
// Close the connections | ||
in.close(); | ||
connection.disconnect(); | ||
|
||
// Convert the StringBuffer to a string | ||
String jsonString = content.toString(); | ||
|
||
// Parse JSON response | ||
Gson gson = new Gson(); | ||
TauriRelease tauriRelease = gson.fromJson(jsonString, TauriRelease.class); | ||
|
||
// Process the data as needed | ||
this.githubRelease = new GithubRelease(); | ||
githubRelease.version = tauriRelease.version; | ||
//githubRelease.publicationDate = new Date(tauriRelease.pub_date); | ||
githubRelease.url = tauriRelease.platforms.get("windows-x86_64").url.replace("nsis.zip", "exe"); | ||
|
||
} | ||
|
||
public GithubRelease getGithubRelease() { | ||
return githubRelease; | ||
} | ||
} |
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,9 @@ | ||
package fr.zelytra.github; | ||
|
||
import java.util.Date; | ||
|
||
public class GithubRelease { | ||
public String version; | ||
public Date publicationDate; | ||
public String url; | ||
} |
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,21 @@ | ||
package fr.zelytra.github; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import java.io.IOException; | ||
|
||
@Path("/github") | ||
public class GithubRest { | ||
|
||
@GET | ||
@Path("/release/download") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getDownloadLink() throws IOException { | ||
GithubApi githubApi = new GithubApi(); | ||
return Response.ok(githubApi.getGithubRelease()).build(); | ||
} | ||
} |
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 @@ | ||
package fr.zelytra.github; | ||
|
||
import java.util.Map; | ||
|
||
public class TauriRelease { | ||
public String version; | ||
public String notes; | ||
public String pub_date; | ||
public Map<String, Platform> platforms; | ||
} | ||
|
||
class Platform { | ||
public String signature; | ||
public String url; | ||
} |
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
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 |
---|---|---|
@@ -1,26 +1,14 @@ | ||
import {reactive} from "vue"; | ||
import axios, {AxiosResponse} from "axios"; | ||
import {GithubRelease, TauriRelease} from "@/objects/Github.ts"; | ||
import {AxiosResponse} from "axios"; | ||
import {GithubRelease} from "@/objects/Github.ts"; | ||
import {HTTPAxios} from "@/objects/HTTPAxios.ts"; | ||
|
||
|
||
export const AppStore = reactive({ | ||
tauriRelease: {} as TauriRelease, | ||
githubRelease: {} as GithubRelease, | ||
init() { | ||
const httpRequest = axios.create({ | ||
headers: { | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Methods": "GET, POST, DELETE", | ||
Authorization: "", | ||
} | ||
}) | ||
httpRequest.get("https://github.com/zelytra/BetterFleet/releases/latest/download/latest.json").then((resonse: AxiosResponse) => { | ||
this.tauriRelease = resonse.data as TauriRelease; | ||
this.githubRelease = { | ||
url: this.tauriRelease.platforms["windows-x86_64"].url.replace("nsis.zip", "exe"), | ||
publicationDate: new Date(this.tauriRelease.pub_date), | ||
version: this.tauriRelease.version | ||
} | ||
new HTTPAxios("github/release/download").get().then((response: AxiosResponse) => { | ||
this.githubRelease = response.data as GithubRelease | ||
}) | ||
}, | ||
}); |