Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return mod version creation datetime in API #195

Merged

Conversation

HebaruSan
Copy link
Contributor

Motivation

Mod authors sometimes delete and replace a version of a mod with a new download. If such a version has already been indexed by an external service (such as CKAN's bot), there's no way to know this has happened (ignoring active notifications for the moment).

This can cause problems for CKAN, since it tracks hashes to ensure that the file the user downloads is the same one the CKAN bot indexed. In KSP-CKAN/CKAN#2337 we implemented a strategy that solved this for GitHub using the release creation timestamp, but the same has not been possible for SpaceDock because the timestamp is unknown.

Changes

Now the mod version API returns a "created" property containing the timestamp when that version was created, in ISO8601 format. This value is already part of the ModVersion data object:

class ModVersion(Base):
__tablename__ = 'modversion'
id = Column(Integer, primary_key = True)
mod_id = Column(Integer, ForeignKey('mod.id'))
mod = relationship('Mod', viewonly=True, backref=backref('modversion', order_by="desc(ModVersion.created)"))
friendly_version = Column(String(64))
gameversion_id = Column(Integer, ForeignKey('gameversion.id'))
gameversion = relationship('GameVersion', viewonly=True, backref=backref('modversion', order_by=id))
created = Column(DateTime)
download_path = Column(String(512))
changelog = Column(Unicode(10000))
sort_index = Column(Integer)
def __init__(self, friendly_version, gameversion_id, download_path):
self.friendly_version = friendly_version
self.gameversion_id = gameversion_id
self.download_path = download_path
self.created = datetime.now()
self.sort_index = 0

The change itself is modeled after a similar property in game_info:

def game_info(game):
return {
"id": game.id,
"name": game.name,
"publisher_id": game.publisher_id,
"short_description": game.short_description,
"description": game.description,
"created": game.created.isoformat(),
"background": game.background,
"bg_offset_x": game.bgOffsetX,
"bg_offset_y": game.bgOffsetY,
"link": game.link
}

This will make it possible for the CKAN bot to tell when it has an old out of date download for a mod on SpaceDock.

@HebaruSan
Copy link
Contributor Author

HebaruSan commented Jul 29, 2019

Since this is trivial, I'm going to go ahead and merge it as a test of the latest attempted fixes to the automatic pulling and restarting of the alpha server. Cross your fingers.

EDIT: We got a /hook/ entry in the log again, but no pull. Need more logging for this.

EDIT II: Maybe the IP address. Config:

# Configure these to determine who can send GitHub-style hook notifications to the site
# to configure an automatic redeployment. Defaults to trusting GitHub and localhost.
hook_ips = 185.199.108.0/22,140.82.112.0/20,192.30.252.0/22,127.0.0.1

Log:

10.150.1.9 - - [29/Jul/2019:23:04:53 +0000] "POST /hook/ HTTP/1.1" 404 195094 "-" "GitHub-Hookshot/20c7c42"

10.150.1.9 is not among the addresses that it considers to be GitHub. I assume that's the reverse proxy, so the hook_ips setting may not be workable anymore. This may be the time to set up a "secret" instead...

@HebaruSan HebaruSan merged commit 60a8c3e into KSP-SpaceDock:alpha Jul 29, 2019
@HebaruSan HebaruSan deleted the feature/api-version-created branch July 29, 2019 23:04
@HebaruSan
Copy link
Contributor Author

On the bright side, the API change worked (note the versions[0].created property):

$ wget -O - https://alpha.spacedock.info/api/mod/1 | python -m json.tool

{
    "author": "HebaruSan",
    "background": null,
    "bg_offset_y": null,
    "default_version_id": 1,
    "description": "See all the transfers that you could choose from your current location at a glance, including the time till the burn and delta V, and turn them into maneuvers with one click.",
    "description_html": "<p>See all the transfers that you could choose from your current location at a glance, including the time till the burn and delta V, and turn them into maneuvers with one click.</p>",
    "donations": "",
    "downloads": 1,
    "followers": 0,
    "game": "Kerbal Space Program",
    "game_id": 1,
    "id": 1,
    "license": "GPL-3.0",
    "name": "Astrogator",
    "shared_authors": [],
    "short_description": "A space-navigational aide for Kerbal Space Program",
    "source_code": "https://github.com/HebaruSan/Astrogator",
    "url": "/mod/1/Astrogator",
    "versions": [
        {
            "changelog": null,
            "created": "2019-07-16T03:03:23.386114",
            "download_path": "/mod/1/Astrogator/download/v0.9.2",
            "friendly_version": "v0.9.2",
            "game_version": "1.0",
            "id": 1
        }
    ],
    "website": "https://forum.kerbalspaceprogram.com/index.php?/topic/155998-*"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant