Modrinth OAuth support

This commit is contained in:
oitsjustjose 2024-12-31 16:19:05 -06:00
commit 52e28067d8
10 changed files with 125 additions and 66 deletions

View file

@ -2,6 +2,7 @@
Houses commonly used dataclasses and Enums
Author: oitsjustjose @ modrinth/curseforge/twitter
"""
from dataclasses import dataclass
from enum import Enum
from typing import List
@ -23,7 +24,7 @@ class Status(Enum):
class Job:
"""A single job"""
github_pat: str
oauth_token: str
curseforge_slug: str
modrinth_id: str
job_id: str = ""

View file

@ -2,6 +2,7 @@
Houses API Tools when communicating with the RESTful API
Author: oitsjustjose @ modrinth/curseforge/twitter
"""
from os import environ as env
from typing import Dict, List, Union
@ -54,7 +55,7 @@ class MgmtApiHelper:
def _dict_to_job(self, data: Dict) -> Job:
"""Converts a dictionary (from mongo) into a Job"""
return Job(
github_pat=self._fernet.decrypt(data["githubPat"]),
oauth_token=self._fernet.decrypt(data["oauthToken"]),
curseforge_slug=data["curseforgeSlug"],
modrinth_id=data["modrinthId"],
logs=data["logs"] if "logs" in data else [],

View file

@ -97,7 +97,7 @@ class FastProvider(MgmtApiLogger):
response = requests.post(
"https://api.modrinth.com/v2/version",
timeout=30,
headers={"Authorization": self._job.github_pat},
headers={"Authorization": self._job.oauth_token},
files=[
("data", (None, payload, None)),
("files", (jar_fn, jar_data, "application/octet-stream")),
@ -179,9 +179,7 @@ class FastProvider(MgmtApiLogger):
status = (
Status.PARTIAL_FAIL
if any_succ and any_fail
else Status.SUCCESS
if any_succ and not any_fail
else Status.FAIL
else Status.SUCCESS if any_succ and not any_fail else Status.FAIL
)
return status
@ -206,5 +204,7 @@ class FastProvider(MgmtApiLogger):
return "downloadUrl" in data[0]
return False
except TimeoutError:
self.logmsg("🕜 Timed out determining if Mod supports third party downloads")
self.logmsg(
"🕜 Timed out determining if Mod supports third party downloads"
)
return False

View file

@ -4,6 +4,7 @@
@description: A SLOW working mod migrator from Curse to Modrinth
This one is used if you're a jerk and disable third party launchers
"""
import json
from os import environ as env
from os import makedirs, path
@ -219,7 +220,7 @@ class SlowProvider(MgmtApiLogger):
response = requests.post(
"https://api.modrinth.com/v2/version",
timeout=30,
headers={"Authorization": self._job.github_pat},
headers={"Authorization": self._job.oauth_token},
files=[
("data", (None, payload, None)),
("files", (fpath, jar_data, "application/octet-stream")),
@ -263,9 +264,7 @@ class SlowProvider(MgmtApiLogger):
status = (
Status.PARTIAL_FAIL
if any_succ and any_fail
else Status.SUCCESS
if any_succ and not any_fail
else Status.FAIL
else Status.SUCCESS if any_succ and not any_fail else Status.FAIL
)
rmdir(f"./out/{self._job.curseforge_slug}")
return status