[Server] Move deck share storage into the database interface (#7837)

The five deck-share commands reached through Servatrice_DatabaseInterface for share lookups, and cmdDeckShareCreate still issued the per-user rate-limit count and the folder deck listing inline. Move DeckShareItemRecord and DeckShareSummaryRecord to Server_DatabaseInterface, declare the share operations plus getDeckSharesCreatedToday and getDeckFilesInFolder there with failing defaults, and switch the commands to the injected interface. The MySQL statements and every response code stay as they were, including the -1-on-failure sentinel for the count.
This commit is contained in:
BruebachL 2026-11-10 12:16:24 +01:00 • committed by GitHub
parent 417e7f7db4
commit ba037cbf04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 131 additions and 65 deletions

View file

@ -26,28 +26,6 @@ class QSqlQuery;
class Servatrice;
/** @brief Metadata of a single deck inside a temporary deck share bundle. */
struct DeckShareItemRecord
{
int id = -1; ///< Database id, used for downloads.
QString name; ///< Deck name.
QStringList tags; ///< Deck tags.
QString bannerCard; ///< Banner card name (deck image).
QString gameFormat; ///< Game format the deck was built for.
QString colorIdentity; ///< Color identity, e.g. "WUBRG".
QString content; ///< Deck content (native format); empty in list queries.
};
/** @brief Summary of a share bundle owned by a user. */
struct DeckShareSummaryRecord
{
int id = -1; ///< Database id, used for revocation.
QString name; ///< Share name.
qint64 creationTime = 0; ///< Unix timestamp at which the share was created.
qint64 expiresAt = 0; ///< Unix timestamp at which the share expires.
int itemCount = 0; ///< Number of decks in the bundle.
};
class Servatrice_DatabaseInterface : public Server_DatabaseInterface
{
Q_OBJECT
@ -156,24 +134,30 @@ public:
int userId,
const QList<DeckShareItemRecord> &items,
int expiryDays,
qint64 &expiresAt);
qint64 &expiresAt) override;
int getDeckSharesCreatedToday(int userId) override;
/** @brief Lists the share bundles created by a user, newest first. */
bool getDeckSharesForUser(int userId, QList<DeckShareSummaryRecord> &shares);
bool getDeckSharesForUser(int userId, QList<DeckShareSummaryRecord> &shares) override;
/**
* @brief Deletes one of a user's own share bundles (cascades to its items).
* @return false if no such bundle belongs to the user.
*/
bool deleteDeckShare(int shareId, int userId);
bool deleteDeckShare(int shareId, int userId) override;
/**
* @brief Looks up a valid (non-expired) share bundle by token.
* @return false if the token is unknown or expired.
*/
bool getDeckShareList(const QString &token, QString &name, qint64 &expiresAt, QList<DeckShareItemRecord> &items);
bool getDeckShareList(const QString &token,
QString &name,
qint64 &expiresAt,
QList<DeckShareItemRecord> &items) override;
/**
* @brief Fetches the content of one item of a valid share bundle.
* @return false if the token is unknown/expired or the item does not belong to the bundle.
*/
bool getDeckShareItem(const QString &token, int itemId, QString &content);
bool getDeckShareItem(const QString &token, int itemId, QString &content) override;
/** @brief Id and color identity of every deck file in a folder, for the share builder. */
bool getDeckFilesInFolder(int folderId, int userId, QList<DeckFileListItem> &files) override;
/** @brief Deletes all expired share bundles (cascades to their items). */
void cleanupExpiredDeckShares();