43 Commits

Author SHA1 Message Date
8ddb999988 Release 0.15.7 2026-01-08 14:26:16 +02:00
cd3379561a fix: restore button visibility 2026-01-08 14:26:01 +02:00
727e6c134a chore: license update 2026-01-08 14:24:22 +02:00
f7f112330b feat: multi loot selector preview 2026-01-08 14:24:09 +02:00
8e52be728e test: add test for 7.4 gear 2026-01-08 13:54:40 +02:00
5025e760c1 Release 0.15.6 2026-01-08 13:46:20 +02:00
35c784bf89 feat: try to migrate to xivapi v2 2026-01-08 13:45:59 +02:00
757c4cc6df feat: allow suggest from interface for ro users 2026-01-08 12:49:34 +02:00
ca24ee298e build: install sbt explicitly 2026-01-08 12:44:51 +02:00
af7a92af35 Release 0.15.5 2026-01-07 14:56:37 +02:00
4c05ceefcd fix: add | to allowed chars 2026-01-07 14:56:01 +02:00
fa43517b16 Release 0.15.4 2024-07-31 15:47:09 +03:00
77e99439e7 chore: fix file formatting 2024-07-31 15:46:56 +03:00
c9eb311cfe bug: remove unreachable code 2024-07-31 15:46:56 +03:00
d662e303c8 feat: xivgear demo support 2024-07-31 15:41:10 +03:00
1c8aaea712 Release 0.15.1 2024-07-22 14:00:59 +03:00
3c8e5f8da8 fix: read itemcost correctly 2024-07-22 13:58:26 +03:00
0bcda3233e feat: dependencies bump- 2024-07-03 13:36:36 +03:00
c4be6f12f1 feat: VPR and PCT support 2024-07-03 13:33:44 +03:00
f3535f6e16 bump libraries 2023-10-20 13:32:55 +03:00
bdf413d494 Release 0.14.0 2022-09-08 03:23:04 +03:00
7a1a73592e bump dependencies 2022-09-08 03:21:14 +03:00
b1ac894ccf add action button to suggest table
Also replace functions with lambdas
2022-07-15 14:15:10 +03:00
6023e86570 Release 0.13.6 2022-06-23 04:41:51 +03:00
a4ab1e49be reset bis links for empty strings 2022-06-23 04:39:21 +03:00
cb99486f8a Release 0.13.5 2022-06-23 04:20:31 +03:00
0e8b95d0dd use strict validator on input strings via api (#15)
It has been reported that that views are vulnerable for XSS because of
missing escaping (or validation). Instead of playing with conversion
from/to escaped/unescaped strings lets just forbid characters via api

This commit includes migration for postgres, sqlite migration is still
missing which will make it impossible to load pages for those parties.

This commit also includes several fixes:
* The issue when empty party could not be loaded
* The issue when link biis is not appllied after editing
* The issue when incorrect bis link has been saved
* The issue when empty password could be applied via api
* The issue when error message is not displayed at the index page

This commit also updates dependencies
2022-06-23 04:19:09 +03:00
118d8faf6b Release 0.13.4 2022-01-31 04:33:33 +03:00
448880ed91 add version to footer 2022-01-31 04:31:45 +03:00
ed3cdd62bd styling 2022-01-31 04:09:17 +03:00
88617eccdf Release 0.13.3 2022-01-23 04:46:44 +03:00
ccbf581332 add more tests
* also make auth provider more powerful
2022-01-23 04:34:39 +03:00
0ab9162cb5 Release 0.13.2 2022-01-22 00:02:23 +03:00
d3018998cd change PUT to POST for party creation request 2022-01-22 00:00:37 +03:00
d4553b2e50 Release 0.13.1 2022-01-21 03:08:34 +03:00
8496d105c0 fix auth generation and blocked https->http requests 2022-01-21 03:06:51 +03:00
ec2cfaea38 Release 0.13.0 2022-01-21 02:31:55 +03:00
963e84f792 api docs review 2022-01-21 02:30:34 +03:00
feea01a47e Release 0.12.2 2022-01-20 00:53:32 +03:00
fcacd9f15c user friednly is required table 2022-01-19 15:09:45 +03:00
b2256784dd move header buttons into one row 2022-01-19 13:42:43 +03:00
fee87ddbc8 more typed actors 2022-01-19 12:19:55 +03:00
dc882b74bf move modals to form validation 2022-01-19 03:04:59 +03:00
132 changed files with 1971 additions and 984 deletions

View File

@ -12,6 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: extract version
id: version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
@ -21,13 +22,24 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
filter: 'Release \d+\.\d+\.\d+'
- name: setup JDK
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17
java-version: 18
- name: install sbt
uses: eclipse-score/apt-install@main
with:
packages: wget
- run: |
wget https://scala.jfrog.io/artifactory/debian/sbt-1.11.7.deb
sudo dpkg -i sbt-1.11.7.deb
- name: create dist
run: make dist
- name: release
uses: softprops/action-gh-release@v1
with:

View File

@ -13,10 +13,20 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: setup JDK
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17
java-version: 18
- name: install sbt
uses: eclipse-score/apt-install@main
with:
packages: wget
- run: |
wget https://scala.jfrog.io/artifactory/debian/sbt-1.11.7.deb
sudo dpkg -i sbt-1.11.7.deb
- name: run tests
run: make tests
run: make tests

View File

@ -1,3 +0,0 @@
* [x] items improvements
* [x] multiple parties support
* [ ] pretty UI

View File

@ -2,7 +2,7 @@ organization := "me.arcanis"
name := "ffxivbis"
scalaVersion := "2.13.6"
scalaVersion := "2.13.12"
scalacOptions ++= Seq("-deprecation", "-feature")

View File

@ -1,25 +1,25 @@
val AkkaVersion = "2.6.18"
val AkkaHttpVersion = "10.2.7"
val ScalaTestVersion = "3.2.10"
val SlickVersion = "3.3.3"
val AkkaVersion = "2.8.6"
val AkkaHttpVersion = "10.5.3"
val ScalaTestVersion = "3.2.19"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.10"
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.4"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.5.6"
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5"
libraryDependencies += "com.typesafe.akka" %% "akka-http" % AkkaHttpVersion
libraryDependencies += "com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion
libraryDependencies += "com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion
libraryDependencies += "com.typesafe.akka" %% "akka-stream" % AkkaVersion
libraryDependencies += "com.github.swagger-akka-http" %% "swagger-akka-http" % "2.6.0"
libraryDependencies += "jakarta.platform" % "jakarta.jakartaee-web-api" % "9.1.0"
libraryDependencies += "com.github.swagger-akka-http" %% "swagger-akka-http" % "2.11.0"
libraryDependencies += "jakarta.platform" % "jakarta.jakartaee-web-api" % "10.0.0"
libraryDependencies += "ch.megard" %% "akka-http-cors" % "1.2.0"
libraryDependencies += "io.spray" %% "spray-json" % "1.3.6"
libraryDependencies += "org.playframework.anorm" %% "anorm" % "2.6.10"
libraryDependencies += "com.zaxxer" % "HikariCP" % "5.0.1" exclude("org.slf4j", "slf4j-api")
libraryDependencies += "org.flywaydb" % "flyway-core" % "8.4.1"
libraryDependencies += "org.xerial" % "sqlite-jdbc" % "3.36.0.3"
libraryDependencies += "org.postgresql" % "postgresql" % "42.3.1"
libraryDependencies += "org.playframework.anorm" %% "anorm" % "2.7.0"
libraryDependencies += "com.zaxxer" % "HikariCP" % "5.1.0" exclude("org.slf4j", "slf4j-api")
libraryDependencies += "org.flywaydb" % "flyway-core" % "9.16.0"
libraryDependencies += "org.xerial" % "sqlite-jdbc" % "3.46.0.0"
libraryDependencies += "org.postgresql" % "postgresql" % "42.7.3"
libraryDependencies += "org.mindrot" % "jbcrypt" % "0.4"
libraryDependencies += "com.google.guava" % "guava" % "31.0.1-jre"

View File

@ -1 +1 @@
sbt.version = 1.5.8
sbt.version = 1.7.1

View File

@ -0,0 +1,3 @@
update parties set party_alias = regexp_replace(party_alias, '[^A-Za-z0-9!@#$%^&*()\-_=+;:'',./? ]', '', 'g');
update players set nick = regexp_replace(nick, '[^A-Za-z0-9!@#$%^&*()\-_=+;:'',./? ]', '', 'g');
update users set username = regexp_replace(username, '[^A-Za-z0-9!@#$%^&*()\-_=+;:'',./? ]', '', 'g');

View File

@ -0,0 +1 @@
update players set bis_link = null where bis_link = '';

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FFXIV loot helper API</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Embed elements Elements via Web Component -->
<script src="https://unpkg.com/@stoplight/elements/web-components.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@stoplight/elements/styles.min.css" type="text/css">
<link rel="shortcut icon" href="/static/favicon.ico">
</head>
<body>
<elements-api
apiDescriptionUrl="/api-docs/swagger.json"
router="hash"
layout="sidebar"
/>
</body>
</html>

View File

@ -6,17 +6,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/favicon.ico" rel="shortcut icon">
<link rel="shortcut icon" href="/static/favicon.ico">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.3/font/bootstrap-icons.css" type="text/css">
<link href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.css" type="text/css">
<link href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" type="text/css">
<link href="/static/styles.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/static/styles.css" type="text/css">
</head>
<body>
@ -86,23 +86,24 @@
<div id="update-bis-dialog" tabindex="-1" role="dialog" class="modal fade">
<div class="modal-dialog" role="document">
<form class="modal-content">
<div class="modal-header">
<form class="modal-content" action="javascript:" onsubmit="updateBis()">
<div class="modal-header form-group row">
<div class="btn-group" role="group" aria-label="Update bis">
<input id="add-piece-btn" name="update-bis" type="radio" class="btn-check" autocomplete="off" checked>
<label class="btn btn-outline-primary" for="add-piece-btn">add piece</label>
<input id="update-bis-btn" name="update-bis" type="radio" class="btn-check" autocomplete="off">
<label class="btn btn-outline-primary" for="update-bis-btn">update bis</label>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
</div>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
</div>
<div class="modal-body">
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="player">player</label>
<div class="col-sm-8">
<select id="player" name="player" class="form-control" title="player"></select>
<select id="player" name="player" class="form-control" title="player" required></select>
</div>
</div>
<div id="piece-row" class="form-group row">
@ -120,14 +121,14 @@
<div id="bis-link-row" class="form-group row" style="display: none">
<label class="col-sm-4 col-form-label" for="bis-link">link</label>
<div class="col-sm-8">
<input id="bis-link" name="link" class="form-control" placeholder="link to bis" onkeyup="disableSubmitBisButton()">
<input id="bis-link" name="link" class="form-control" placeholder="link to bis">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">close</button>
<button id="submit-add-bis-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="addPiece()" disabled>add</button>
<button id="submit-update-bis-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="setBis()" style="display: none" disabled>set</button>
<button id="submit-add-bis-btn" type="submit" class="btn btn-primary">add</button>
<button id="submit-set-bis-btn" type="submit" class="btn btn-primary" style="display: none">set</button>
</div>
</div>
</form>
@ -138,10 +139,11 @@
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
<ul class="nav">
<li><a class="nav-link" href="/" title="home">home</a></li>
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
</ul>
<ul class="nav">
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a id="sources-link" class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/releases" title="releases list">releases</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/issues" title="issues tracker">report a bug</a></li>
</ul>
@ -155,11 +157,11 @@
<script src="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/resizable/bootstrap-table-resizable.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/extensions/resizable/bootstrap-table-resizable.js"></script>
<script src="/static/utils.js"></script>
<script src="/static/load.js"></script>
@ -171,7 +173,7 @@
const updateButton = $("#update-btn");
const submitAddBisButton = $("#submit-add-bis-btn");
const submitUpdateBisButton = $("#submit-update-bis-btn");
const submitSetBisButton = $("#submit-set-bis-btn");
const updateBisDialog = $("#update-bis-dialog");
const addPieceButton = $("#add-piece-btn");
@ -205,15 +207,11 @@
}),
type: "POST",
contentType: "application/json",
success: function (_) { reload(); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
success: _ => { reload(); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
}
function disableSubmitBisButton() {
const nonEmpty = (playerInput.val() !== null); // well lol
submitUpdateBisButton.attr("disabled", !(nonEmpty && linkInput.val()));
submitAddBisButton.attr("disabled", !(nonEmpty));
updateBisDialog.modal("hide");
return true; // action expects boolean result
}
function hideControls() {
@ -222,20 +220,24 @@
}
function hideLinkPart() {
disableSubmitBisButton();
bisLinkRow.hide();
submitUpdateBisButton.hide();
linkInput.prop("required", false);
submitSetBisButton.hide();
pieceRow.show();
pieceTypeRow.show();
pieceInput.prop("required", true);
pieceTypeInput.prop("required", true);
submitAddBisButton.show();
}
function hidePiecePart() {
disableSubmitBisButton();
bisLinkRow.show();
submitUpdateBisButton.show();
linkInput.prop("required", true);
submitSetBisButton.show();
pieceRow.hide();
pieceTypeRow.hide();
pieceInput.prop("required", false);
pieceTypeInput.prop("required", false);
submitAddBisButton.hide();
}
@ -245,9 +247,9 @@
url: `/api/v1/party/${partyId}`,
type: "GET",
dataType: "json",
success: function (data) {
const items = data.map(function (player) {
return player.bis.map(function (loot) {
success: response => {
const items = response.map(player => {
return player.bis.map(loot => {
return {
nick: player.nick,
job: player.job,
@ -256,12 +258,12 @@
};
});
});
const payload = items.reduce(function (left, right) { return left.concat(right); }, []);
const payload = items.reduce((left, right) => { return left.concat(right); }, []);
table.bootstrapTable("load", payload);
table.bootstrapTable("uncheckAll");
table.bootstrapTable("hideLoading");
const options = data.map(function (player) {
const options = response.map(player => {
const option = document.createElement("option");
option.innerText = formatPlayerId(player);
option.dataset.nick = player.nick;
@ -269,15 +271,14 @@
return option;
});
playerInput.empty().append(options);
disableSubmitBisButton();
},
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
}
function removePiece() {
const pieces = table.bootstrapTable("getSelections");
pieces.map(function (loot) {
pieces.map(loot => {
$.ajax({
url: `/api/v1/party/${partyId}/bis`,
data: JSON.stringify({
@ -295,8 +296,8 @@
}),
type: "POST",
contentType: "application/json",
success: function (_) { reload(); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
success: _ => { reload(); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
});
}
@ -324,26 +325,40 @@
}),
type: "PUT",
contentType: "application/json",
success: function (_) { reload(); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
success: _ => { reload(); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
updateBisDialog.modal("hide");
return true; // action expects boolean result
}
$(function () {
function updateBis() {
if (updateBisButton.is(":checked")) {
return setBis();
}
if (addPieceButton.is(":checked")) {
return addPiece();
}
return false; // should not happen
}
$(() => {
setupFormClear(updateBisDialog, reset);
setupRemoveButton(table, removeButton);
loadHeader(partyId);
loadVersion();
loadTypes("/api/v1/types/pieces", pieceInput);
loadTypes("/api/v1/types/pieces/types", pieceTypeInput);
hideControls();
updateBisButton.click(function () { reset(); });
addPieceButton.click(function () { reset(); });
updateBisButton.click(() => { reset(); });
addPieceButton.click(() => { reset(); });
table.bootstrapTable({});
reload();
reset();
});
</script>

View File

@ -6,11 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/favicon.ico" rel="shortcut icon">
<link rel="shortcut icon" href="/static/favicon.ico">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link href="/static/styles.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/static/styles.css" type="text/css">
</head>
<body>
@ -71,10 +71,12 @@
<div class="container">
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
<ul class="nav"></ul>
<ul class="nav">
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
</ul>
<ul class="nav">
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a id="sources-link" class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/releases" title="releases list">releases</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/issues" title="issues tracker">report a bug</a></li>
</ul>
@ -85,6 +87,9 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="/static/utils.js"></script>
<script src="/static/load.js"></script>
<script>
const signinButton = $("#signin-btn");
const signupButton = $("#signup-btn");
@ -122,7 +127,7 @@
password: passwordInput.val(),
permission: "admin",
}),
type: "PUT",
type: "POST",
contentType: "application/json",
dataType: "json",
success: function (data) {
@ -174,6 +179,8 @@
}
$(function () {
loadVersion();
signinButton.click(function () { reset(); });
signupButton.click(function () { reset(); });
});

View File

@ -6,17 +6,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/favicon.ico" rel="shortcut icon">
<link rel="shortcut icon" href="/static/favicon.ico">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.3/font/bootstrap-icons.css" type="text/css">
<link href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.css" type="text/css">
<link href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" type="text/css">
<link href="/static/styles.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/static/styles.css" type="text/css">
</head>
<body>
@ -41,7 +41,7 @@
<div class="container">
<div id="toolbar">
<button id="add-btn" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#add-loot-dialog" hidden>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#add-loot-dialog">
<i class="bi bi-plus"></i> add
</button>
<button class="btn btn-secondary" onclick="reload()">
@ -88,35 +88,35 @@
<div id="add-loot-dialog" tabindex="-1" role="dialog" class="modal fade">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<form class="modal-content" action="javascript:" onsubmit="addLootModal()">
<div class="modal-header">
<h4 class="modal-title">add looted piece</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
</div>
<form class="modal-body">
<div class="modal-body">
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="player">player</label>
<div class="col-sm-8">
<select id="player" name="player" class="form-control" title="player"></select>
<select id="player" name="player" class="form-control" title="player" required></select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="piece">piece</label>
<div class="col-sm-8">
<select id="piece" name="piece" class="form-control" title="piece"></select>
<select id="piece" name="piece" class="form-control" title="piece" required></select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="piece-type">piece type</label>
<div class="col-sm-8">
<select id="piece-type" name="pieceType" class="form-control" title="pieceType"></select>
<select id="piece-type" name="pieceType" class="form-control" title="pieceType" required></select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="job">job</label>
<div class="col-sm-8">
<select id="job" name="job" class="form-control" title="job"></select>
<select id="job" name="job" class="form-control" title="job" required></select>
</div>
</div>
<div class="form-group row">
@ -132,6 +132,7 @@
<table id="stats" class="table table-striped table-hover">
<thead class="table-primary">
<tr>
<th data-formatter="addLootFormatter"></th>
<th data-field="nick">nick</th>
<th data-field="job">job</th>
<th data-field="isRequired">required</th>
@ -141,14 +142,14 @@
</tr>
</thead>
</table>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">close</button>
<button type="button" class="btn btn-secondary" onclick="suggestLoot()">suggest</button>
<button id="submit-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="addLoot()" disabled>add</button>
<button id="add-btn" type="submit" class="btn btn-primary">add</button>
</div>
</div>
</form>
</div>
</div>
@ -156,10 +157,11 @@
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
<ul class="nav">
<li><a class="nav-link" href="/" title="home">home</a></li>
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
</ul>
<ul class="nav">
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a id="sources-link" class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/releases" title="releases list">releases</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/issues" title="issues tracker">report a bug</a></li>
</ul>
@ -173,11 +175,11 @@
<script src="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/resizable/bootstrap-table-resizable.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/extensions/resizable/bootstrap-table-resizable.js"></script>
<script src="/static/utils.js"></script>
<script src="/static/load.js"></script>
@ -189,7 +191,6 @@
const addButton = $("#add-btn");
const removeButton = $("#remove-btn");
const submitLootButton = $("#submit-btn");
const addLootDialog = $("#add-loot-dialog");
const freeLootInput = $("#free-loot");
@ -198,31 +199,43 @@
const pieceTypeInput = $("#piece-type");
const playerInput = $("#player");
function addLoot() {
const player = getCurrentOption(playerInput);
function addLoot(nick, job) {
$.ajax({
url: `/api/v1/party/${partyId}/loot`,
data: JSON.stringify({
action: "add",
piece: {
pieceType: pieceTypeInput.val(),
job: player.dataset.job,
job: job,
piece: pieceInput.val(),
},
playerId: {
partyId: partyId,
nick: player.dataset.nick,
job: player.dataset.job,
nick: nick,
job: job,
},
isFreeLoot: freeLootInput.is(":checked"),
}),
type: "POST",
contentType: "application/json",
success: function (_) { reload(); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
success: _ => {
addLootDialog.modal("hide");
reload();
},
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
}
function addLootFormatter(value, row, index) {
return `<button type="button" class="btn btn-primary" onclick="addLoot('${row.nick}', '${row.job}')"><i class="bi bi-plus"></i></button>`;
}
function addLootModal() {
const player = getCurrentOption(playerInput);
addLoot(player.dataset.nick, player.dataset.job);
return true; // action expects boolean result
}
function hideControls() {
addButton.attr("hidden", isReadOnly);
removeButton.attr("hidden", isReadOnly);
@ -234,9 +247,9 @@
url: `/api/v1/party/${partyId}`,
type: "GET",
dataType: "json",
success: function (data) {
const items = data.map(function (player) {
return player.loot.map(function (loot) {
success: response => {
const items = response.map(player => {
return player.loot.map(loot => {
return {
nick: player.nick,
job: player.job,
@ -247,12 +260,12 @@
};
});
});
const payload = items.reduce(function (left, right) { return left.concat(right); }, []);
const payload = items.reduce((left, right) => { return left.concat(right); }, []);
table.bootstrapTable("load", payload);
table.bootstrapTable("uncheckAll");
table.bootstrapTable("hideLoading");
const options = data.map(function (player) {
const options = response.map(player => {
const option = document.createElement("option");
option.innerText = formatPlayerId(player);
option.dataset.nick = player.nick;
@ -260,15 +273,14 @@
return option;
});
playerInput.empty().append(options);
submitLootButton.attr("disabled", options.length === 0);
},
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
}
function removeLoot() {
const pieces = table.bootstrapTable("getSelections");
pieces.map(function (loot) {
pieces.map(loot => {
$.ajax({
url: `/api/v1/party/${partyId}/loot`,
data: JSON.stringify({
@ -287,8 +299,8 @@
}),
type: "POST",
contentType: "application/json",
success: function (_) { reload(); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
success: _ => { reload(); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
});
}
@ -305,12 +317,12 @@
type: "PUT",
contentType: "application/json",
dataType: "json",
success: function (data) {
const payload = data.map(function (stat) {
success: response => {
const payload = response.map(stat => {
return {
nick: stat.nick,
job: stat.job,
isRequired: stat.isRequired,
isRequired: stat.isRequired ? "yes" : "no",
lootCount: stat.lootCount,
lootCountBiS: stat.lootCountBiS,
lootCountTotal: stat.lootCountTotal,
@ -320,14 +332,15 @@
stats.bootstrapTable("uncheckAll");
stats.bootstrapTable("hideLoading");
},
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
}
$(function () {
$(() => {
setupFormClear(addLootDialog);
setupRemoveButton(table, removeButton);
loadVersion();
loadHeader(partyId);
loadTypes("/api/v1/types/jobs/all", jobInput);
loadTypes("/api/v1/types/pieces", pieceInput);

View File

@ -6,17 +6,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/favicon.ico" rel="shortcut icon">
<link rel="shortcut icon" href="/static/favicon.ico">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.3/font/bootstrap-icons.css" type="text/css">
<link href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.css" type="text/css">
<link href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" type="text/css">
<link href="/static/styles.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/static/styles.css" type="text/css">
</head>
<body>
@ -84,23 +84,23 @@
<div id="add-player-dialog" tabindex="-1" role="dialog" class="modal fade">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form class="modal-content" action="javascript:" onsubmit="addPlayer()">
<div class="modal-header">
<h4 class="modal-title">add new player</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
</div>
<form class="modal-body">
<div class="modal-body">
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="nick">player name</label>
<div class="col-sm-8">
<input id="nick" name="nick" class="form-control" placeholder="nick" onkeyup="disableAddPlayerForm()">
<input id="nick" name="nick" class="form-control" placeholder="nick" required>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="job">player job</label>
<div class="col-sm-8">
<select id="job" name="job" class="form-control" title="job"></select>
<select id="job" name="job" class="form-control" title="job" required></select>
</div>
</div>
<div class="form-group row">
@ -115,13 +115,13 @@
<input id="priority" name="priority" type="number" class="form-control" value="0">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">close</button>
<button id="submit-player-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="addPlayer()" disabled>add</button>
<button type="submit" class="btn btn-primary">add</button>
</div>
</div>
</form>
</div>
</div>
@ -129,10 +129,11 @@
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
<ul class="nav">
<li><a class="nav-link" href="/" title="home">home</a></li>
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
</ul>
<ul class="nav">
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a id="sources-link" class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/releases" title="releases list">releases</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/issues" title="issues tracker">report a bug</a></li>
</ul>
@ -146,11 +147,11 @@
<script src="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/resizable/bootstrap-table-resizable.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/extensions/resizable/bootstrap-table-resizable.js"></script>
<script src="/static/utils.js"></script>
<script src="/static/load.js"></script>
@ -162,7 +163,6 @@
const removeButton = $("#remove-btn");
const addPlayerDialog = $("#add-player-dialog");
const submitPlayerButton = $("#submit-player-btn");
const jobInput = $("#job");
const linkInput = $("#link");
@ -184,9 +184,11 @@
}),
type: "POST",
contentType: "application/json",
success: function (_) { reload(); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
success: _ => { reload(); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
addPlayerDialog.modal("hide");
return true; // action expects boolean result
}
function bisLinkFormatter(link, row) {
@ -197,10 +199,6 @@
}
}
function disableAddPlayerForm() {
submitPlayerButton.attr("disabled", !nickInput.val());
}
function hideControls() {
addButton.attr("hidden", isReadOnly);
removeButton.attr("hidden", isReadOnly);
@ -212,18 +210,18 @@
url: `/api/v1/party/${partyId}`,
type: "GET",
dataType: "json",
success: function (data) {
table.bootstrapTable("load", data);
success: response => {
table.bootstrapTable("load", response);
table.bootstrapTable("uncheckAll");
table.bootstrapTable("hideLoading");
},
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
}
function removePlayers() {
const players = table.bootstrapTable("getSelections");
players.map(function (player) {
players.map(player => {
$.ajax({
url: `/api/v1/party/${partyId}`,
data: JSON.stringify({
@ -236,16 +234,17 @@
}),
type: "POST",
contentType: "application/json",
success: function (_) { reload(); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
success: _ => { reload(); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
});
}
$(function () {
$(() => {
setupFormClear(addPlayerDialog);
setupRemoveButton(table, removeButton);
loadVersion();
loadHeader(partyId);
loadTypes("/api/v1/types/jobs", jobInput);

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FFXIV loot helper API</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet" type="text/css">
<link href="/static/favicon.ico" rel="shortcut icon">
</head>
<body>
<redoc spec-url="/api-docs/swagger.json"></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
</body>
</html>

View File

@ -6,17 +6,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/favicon.ico" rel="shortcut icon">
<link rel="shortcut icon" href="/static/favicon.ico">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" type="text/css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.3/font/bootstrap-icons.css" type="text/css">
<link href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.css" type="text/css">
<link href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.css" type="text/css">
<link href="/static/styles.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/static/styles.css" type="text/css">
</head>
<body>
@ -84,38 +84,38 @@
<div id="add-user-dialog" tabindex="-1" role="dialog" class="modal fade">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form class="modal-content" action="javascript:" onsubmit="addUser()">
<div class="modal-header">
<h4 class="modal-title">add new user</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
</div>
<form class="modal-body">
<div class="modal-body">
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="username">login</label>
<div class="col-sm-8">
<input id="username" name="username" class="form-control" placeholder="username" onkeyup="disableAddUserForm()">
<input id="username" name="username" class="form-control" placeholder="username" required>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="password">password</label>
<div class="col-sm-8">
<input id="password" name="password" type="password" class="form-control" placeholder="password" onkeyup="disableAddUserForm()">
<input id="password" name="password" type="password" class="form-control" placeholder="password" required>
</div>
</div>
<div class="form-group row">
<label class="col-sm-4 col-form-label" for="permission">permission</label>
<div class="col-sm-8">
<select id="permission" name="permission" class="form-control" title="permission"></select>
<select id="permission" name="permission" class="form-control" title="permission" required></select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">close</button>
<button id="submit-btn" type="button" class="btn btn-primary" data-bs-dismiss="modal" onclick="addUser()" disabled>add</button>
<button type="submit" class="btn btn-primary">add</button>
</div>
</div>
</form>
</div>
</div>
@ -123,10 +123,11 @@
<footer class="d-flex flex-wrap justify-content-between align-items-center border-top">
<ul class="nav">
<li><a class="nav-link" href="/" title="home">home</a></li>
<li><a class="nav-link" href="/api-docs" title="api">api</a></li>
</ul>
<ul class="nav">
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a id="sources-link" class="nav-link" href="https://github.com/arcan1s/ffxivbis" title="sources">ffxivbis</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/releases" title="releases list">releases</a></li>
<li><a class="nav-link" href="https://github.com/arcan1s/ffxivbis/issues" title="issues tracker">report a bug</a></li>
</ul>
@ -140,11 +141,11 @@
<script src="https://unpkg.com/jquery-resizable-columns@0.2.3/dist/jquery.resizableColumns.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/resizable/bootstrap-table-resizable.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.20.2/dist/extensions/resizable/bootstrap-table-resizable.js"></script>
<script src="/static/utils.js"></script>
<script src="/static/load.js"></script>
@ -156,7 +157,6 @@
const removeButton = $("#remove-btn");
const addUserDialog = $("#add-user-dialog");
const submitUserButton = $("#submit-btn");
const usernameInput = $("#username");
const passwordInput = $("#password");
@ -173,13 +173,11 @@
}),
type: "POST",
contentType: "application/json",
success: function (_) { reload(); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
success: _ => { reload(); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
}
function disableAddUserForm() {
submitUserButton.attr("disabled", !(usernameInput.val() && passwordInput.val()));
addUserDialog.modal("hide");
return true; // action expects boolean result
}
function hideControls() {
@ -193,31 +191,32 @@
url: `/api/v1/party/${partyId}/users`,
type: "GET",
dataType: "json",
success: function (data) {
table.bootstrapTable("load", data);
success: response => {
table.bootstrapTable("load", response);
table.bootstrapTable("uncheckAll");
table.bootstrapTable("hideLoading");
},
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
}
function removeUsers() {
const users = table.bootstrapTable("getSelections");
users.map(function (user) {
users.map(user => {
$.ajax({
url: `/api/v1/party/${partyId}/users/${user.username}`,
type: "DELETE",
success: function (_) { reload(); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
success: _ => { reload(); },
error: (jqXHR, _, errorThrown) => { requestAlert(jqXHR, errorThrown); },
});
});
}
$(function () {
$(() => {
setupFormClear(addUserDialog);
setupRemoveButton(table, removeButton);
loadVersion();
loadHeader(partyId);
loadTypes("/api/v1/types/permissions", permissionInput);

View File

@ -12,5 +12,6 @@
</logger>
<logger name="org.flywaydb.core.internal" level="INFO" />
<logger name="com.zaxxer.hikari.pool" level="INFO" />
<logger name="io.swagger" level="INFO" />
</configuration>

View File

@ -4,7 +4,7 @@ me.arcanis.ffxivbis {
include "item_data.json"
# xivapi base url, string, required
xivapi-url = "https://xivapi.com"
xivapi-url = "https://v2.xivapi.com"
# xivapi developer key, string, optional
#xivapi-key = "abcdef"
}
@ -50,6 +50,7 @@ me.arcanis.ffxivbis {
#hostname = "127.0.0.1:8000"
# enable head requests for GET requests
enable-head-requests = yes
schemes = ["http"]
authorization-cache {
# maximum amount of cached logins

View File

@ -36,8 +36,18 @@ function loadTypes(url, selector) {
});
}
function loadVersion() {
$.ajax({
url: "/api/v1/status",
type: "GET",
dataType: "json",
success: function (data) { $("#sources-link").text(`ffxivbis ${data.version}`); },
error: function (jqXHR, _, errorThrown) { requestAlert(jqXHR, errorThrown); },
});
}
function setupFormClear(dialog, reset) {
dialog.on("shown.bs.modal", function () {
dialog.on("hide.bs.modal", function () {
$(this).find("form").trigger("reset");
$(this).find("table").bootstrapTable("removeAll");
if (reset) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -50,7 +50,7 @@ class Application(context: ActorContext[Nothing]) extends AbstractBehavior[Nothi
val party = context.spawn(PartyService(storage), "party")
val http = new RootEndpoint(context.system, party, bisProvider)
val flow = Route.toFlow(http.route)(context.system)
val flow = Route.toFlow(http.routes)(context.system)
Http(context.system).newServerAt(host, port).bindFlow(flow)
case Success(result) =>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -10,8 +10,7 @@ package me.arcanis.ffxivbis
import akka.actor.typed.ActorSystem
object ffxivbis {
object ffxivbis extends App {
def main(args: Array[String]): Unit =
ActorSystem[Nothing](Application(), "ffxivbis", Configuration.load())
ActorSystem[Nothing](Application(), "ffxivbis", Configuration.load())
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -37,23 +37,16 @@ trait Authorization {
def authAdmin(partyId: String)(username: String, password: String)(implicit
executionContext: ExecutionContext
): Future[Option[User]] =
authenticator(Permission.admin, partyId)(username, password)
auth.authenticator(Permission.admin, partyId)(username, password)
def authGet(partyId: String)(username: String, password: String)(implicit
executionContext: ExecutionContext
): Future[Option[User]] =
authenticator(Permission.get, partyId)(username, password)
auth.authenticator(Permission.get, partyId)(username, password)
def authPost(partyId: String)(username: String, password: String)(implicit
executionContext: ExecutionContext
): Future[Option[User]] =
authenticator(Permission.post, partyId)(username, password)
auth.authenticator(Permission.post, partyId)(username, password)
private def authenticator(scope: Permission.Value, partyId: String)(username: String, password: String)(implicit
executionContext: ExecutionContext
): Future[Option[User]] =
auth.get(partyId, username).map {
case Some(user) if user.verify(password) && user.verityScope(scope) => Some(user)
case _ => None
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -13,20 +13,33 @@ import akka.actor.typed.{ActorRef, Scheduler}
import akka.util.Timeout
import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache}
import com.typesafe.config.Config
import me.arcanis.ffxivbis.messages.{GetUser, Message}
import me.arcanis.ffxivbis.models.User
import me.arcanis.ffxivbis.messages.DatabaseMessage.GetUser
import me.arcanis.ffxivbis.messages.Message
import me.arcanis.ffxivbis.models.{Permission, User}
import java.util.concurrent.TimeUnit
import scala.concurrent.Future
import scala.concurrent.{ExecutionContext, Future}
trait AuthorizationProvider {
def get(partyId: String, username: String): Future[Option[User]]
def authenticator[T](scope: Permission.Value, partyId: String)(username: String, password: String)(implicit
executionContext: ExecutionContext,
extractor: User => T
): Future[Option[T]] =
get(partyId, username).map {
case Some(user) if user.verify(password) && user.verityScope(scope) => Some(extractor(user))
case _ => None
}
}
object AuthorizationProvider {
def apply(config: Config, storage: ActorRef[Message], timeout: Timeout, scheduler: Scheduler): AuthorizationProvider =
def apply(config: Config, storage: ActorRef[Message])(implicit
timeout: Timeout,
scheduler: Scheduler
): AuthorizationProvider =
new AuthorizationProvider {
private val cacheSize = config.getInt("me.arcanis.ffxivbis.web.authorization-cache.cache-size")
private val cacheTimeout =

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,8 +12,10 @@ import akka.actor.typed.{ActorRef, ActorSystem, Scheduler}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server._
import akka.util.Timeout
import ch.megard.akka.http.cors.scaladsl.CorsDirectives.cors
import com.typesafe.scalalogging.StrictLogging
import me.arcanis.ffxivbis.http.api.v1.RootApiV1Endpoint
import me.arcanis.ffxivbis.http.api.v2.RootApiV2Endpoint
import me.arcanis.ffxivbis.http.view.RootView
import me.arcanis.ffxivbis.messages.{BiSProviderMessage, Message}
@ -27,34 +29,38 @@ class RootEndpoint(system: ActorSystem[Nothing], storage: ActorRef[Message], pro
implicit val scheduler: Scheduler = system.scheduler
implicit val timeout: Timeout = config.getTimeout("me.arcanis.ffxivbis.settings.request-timeout")
private val auth = AuthorizationProvider(config, storage, timeout, scheduler)
private val auth = AuthorizationProvider(config, storage)
private val rootApiV1Endpoint = new RootApiV1Endpoint(storage, auth, provider, config)
private val rootApiV2Endpoint = new RootApiV2Endpoint(storage, auth)
private val rootView = new RootView(auth)
private val swagger = new Swagger(config)
def route: Route =
def routes: Route =
withHttpLog {
ignoreTrailingSlash {
apiRoute ~ htmlRoute ~ swagger.routes ~ swaggerUIRoute
cors() {
apiRoutes ~ htmlRoutes ~ swagger.routes ~ swaggerUIRoutes
}
}
}
private def apiRoute: Route =
private def apiRoutes: Route =
pathPrefix("api") {
pathPrefix(Segment) {
case "v1" => rootApiV1Endpoint.route
case "v1" => rootApiV1Endpoint.routes
case "v2" => rootApiV2Endpoint.routes
case _ => reject
}
}
private def htmlRoute: Route =
private def htmlRoutes: Route =
pathPrefix("static") {
getFromResourceDirectory("static")
} ~ rootView.route
} ~ rootView.routes
private def swaggerUIRoute: Route =
private def swaggerUIRoutes: Route =
path("api-docs") {
getFromResource("html/redoc.html")
getFromResource("html/api.html")
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -14,6 +14,7 @@ import com.typesafe.config.Config
import io.swagger.v3.oas.models.security.SecurityScheme
import scala.io.Source
import scala.jdk.CollectionConverters._
class Swagger(config: Config) extends SwaggerHttpService {
@ -38,13 +39,15 @@ class Swagger(config: Config) extends SwaggerHttpService {
if (config.hasPath("me.arcanis.ffxivbis.web.hostname")) config.getString("me.arcanis.ffxivbis.web.hostname")
else s"${config.getString("me.arcanis.ffxivbis.web.host")}:${config.getInt("me.arcanis.ffxivbis.web.port")}"
override val schemes: List[String] = config.getStringList("me.arcanis.ffxivbis.web.schemes").asScala.toList
private val basicAuth = new SecurityScheme()
.description("basic http auth")
.`type`(SecurityScheme.Type.HTTP)
.in(SecurityScheme.In.HEADER)
.scheme("bearer")
override val securitySchemes: Map[String, SecurityScheme] = Map("basic auth" -> basicAuth)
.scheme("basic")
override val securitySchemes: Map[String, SecurityScheme] = Map("basic" -> basicAuth)
override val unwantedDefinitions: Seq[String] =
Seq("Function1", "Function1RequestContextFutureRouteResult")
Seq("Function1", "Function1RequestContextFutureRouteResult", "SeqLootModel", "SeqPieceModel")
}

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.http
import scala.collection.immutable.HashSet
trait ValidatorHelper {
def isValidString(string: String): Boolean = string.nonEmpty && string.forall(isValidSymbol)
def isValidSymbol(char: Char): Boolean =
char.isLetterOrDigit || ValidatorHelper.VALID_CHARACTERS.contains(char)
}
object ValidatorHelper {
final val VALID_CHARACTERS = HashSet.from("!@#$%^&*()-_=+;:',./?| ")
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -40,7 +40,7 @@ class BiSEndpoint(
with Authorization
with JsonSupport {
def route: Route = createBiS ~ getBiS ~ modifyBiS
def routes: Route = createBiS ~ getBiS ~ modifyBiS
@PUT
@Path("party/{partyId}/bis")
@ -49,7 +49,12 @@ class BiSEndpoint(
summary = "create best in slot",
description = "Create the best in slot set",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
requestBody = new RequestBody(
description = "player best in slot description",
@ -79,7 +84,7 @@ class BiSEndpoint(
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
tags = Array("best in slot"),
)
def createBiS: Route =
@ -105,7 +110,12 @@ class BiSEndpoint(
summary = "get best in slot",
description = "Return the best in slot items",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
new Parameter(
name = "nick",
in = ParameterIn.QUERY,
@ -140,7 +150,7 @@ class BiSEndpoint(
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
tags = Array("best in slot"),
)
def getBiS: Route =
@ -167,7 +177,12 @@ class BiSEndpoint(
summary = "modify best in slot",
description = "Add or remove an item from the best in slot",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
requestBody = new RequestBody(
description = "action and piece description",
@ -197,7 +212,7 @@ class BiSEndpoint(
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
tags = Array("best in slot"),
)
def modifyBiS: Route =

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -11,25 +11,45 @@ package me.arcanis.ffxivbis.http.api.v1
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server._
import ch.megard.akka.http.cors.scaladsl.CorsDirectives.corsRejectionHandler
import com.typesafe.scalalogging.StrictLogging
import me.arcanis.ffxivbis.http.api.v1.json._
import spray.json._
import scala.util.control.NonFatal
trait HttpHandler extends StrictLogging { this: JsonSupport =>
def exceptionHandler: ExceptionHandler = ExceptionHandler {
case ex: IllegalArgumentException =>
complete(StatusCodes.BadRequest, ErrorModel(ex.getMessage))
case exception: IllegalArgumentException =>
complete(StatusCodes.BadRequest, ErrorModel(exception.getMessage))
case other: Exception =>
case NonFatal(other) =>
logger.error("exception during request completion", other)
complete(StatusCodes.InternalServerError, ErrorModel("unknown server error"))
}
def rejectionHandler: RejectionHandler =
RejectionHandler.default
RejectionHandler
.newBuilder()
.handleAll[MethodRejection] { rejections =>
val (methods, names) = rejections.map(r => r.supported -> r.supported.name).unzip
respondWithHeader(headers.Allow(methods)) {
options {
complete(StatusCodes.OK, HttpEntity.Empty)
} ~
complete(
StatusCodes.MethodNotAllowed,
s"HTTP method not allowed, supported methods: ${names.mkString(", ")}"
)
}
}
.result()
.withFallback(corsRejectionHandler)
.seal
.mapRejectionResponse {
case response @ HttpResponse(_, _, entity: HttpEntity.Strict, _) =>
case response @ HttpResponse(_, _, entity: HttpEntity.Strict, _) if entity.data.nonEmpty =>
val message = ErrorModel(entity.data.utf8String).toJson
response.withEntity(HttpEntity(ContentTypes.`application/json`, message.compactPrint))
case other => other

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -37,7 +37,7 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
with JsonSupport
with HttpHandler {
def route: Route = getLoot ~ modifyLoot ~ suggestLoot
def routes: Route = getLoot ~ modifyLoot ~ suggestLoot
@GET
@Path("party/{partyId}/loot")
@ -46,7 +46,12 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
summary = "get loot list",
description = "Return the looted items",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
new Parameter(
name = "nick",
in = ParameterIn.QUERY,
@ -81,7 +86,7 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
tags = Array("loot"),
)
def getLoot: Route =
@ -107,7 +112,12 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
summary = "modify loot list",
description = "Add or remove an item from the loot list",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
requestBody = new RequestBody(
description = "action and piece description",
@ -137,7 +147,7 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
tags = Array("loot"),
)
def modifyLoot: Route =
@ -164,7 +174,12 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
summary = "suggest loot",
description = "Suggest loot piece to party",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
requestBody = new RequestBody(
description = "piece description",
@ -202,7 +217,7 @@ class LootEndpoint(override val storage: ActorRef[Message], override val auth: A
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
tags = Array("loot"),
)
def suggestLoot: Route =

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -40,7 +40,7 @@ class PartyEndpoint(
with JsonSupport
with HttpHandler {
def route: Route = getPartyDescription ~ modifyPartyDescription
def routes: Route = getPartyDescription ~ modifyPartyDescription
@GET
@Path("party/{partyId}/description")
@ -49,7 +49,12 @@ class PartyEndpoint(
summary = "get party description",
description = "Return the party description",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
responses = Array(
new ApiResponse(
@ -73,7 +78,7 @@ class PartyEndpoint(
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
tags = Array("party"),
)
def getPartyDescription: Route =
@ -96,7 +101,12 @@ class PartyEndpoint(
summary = "modify party description",
description = "Edit party description",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
requestBody = new RequestBody(
description = "new party description",
@ -126,7 +136,7 @@ class PartyEndpoint(
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
tags = Array("party"),
)
def modifyPartyDescription: Route =

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -41,7 +41,7 @@ class PlayerEndpoint(
with JsonSupport
with HttpHandler {
def route: Route = getParty ~ getPartyStats ~ modifyParty
def routes: Route = getParty ~ getPartyStats ~ modifyParty
@GET
@Path("party/{partyId}")
@ -50,7 +50,12 @@ class PlayerEndpoint(
summary = "get party",
description = "Return the players who belong to the party",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
new Parameter(
name = "nick",
in = ParameterIn.QUERY,
@ -85,7 +90,7 @@ class PlayerEndpoint(
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
tags = Array("party"),
)
def getParty: Route =
@ -111,7 +116,12 @@ class PlayerEndpoint(
summary = "get party statistics",
description = "Return the party statistics",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
new Parameter(
name = "nick",
in = ParameterIn.QUERY,
@ -146,7 +156,7 @@ class PlayerEndpoint(
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
tags = Array("party"),
)
def getPartyStats: Route =
@ -172,7 +182,12 @@ class PlayerEndpoint(
summary = "modify party",
description = "Add or remove a player from party list",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
requestBody = new RequestBody(
description = "player description",
@ -202,7 +217,7 @@ class PlayerEndpoint(
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("post"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("post"))),
tags = Array("party"),
)
def modifyParty: Route =

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -36,11 +36,11 @@ class RootApiV1Endpoint(
private val typesEndpoint = new TypesEndpoint(config)
private val userEndpoint = new UserEndpoint(storage, auth)
def route: Route =
def routes: Route =
handleExceptions(exceptionHandler) {
handleRejections(rejectionHandler) {
biSEndpoint.route ~ lootEndpoint.route ~ partyEndpoint.route ~ playerEndpoint.route ~
statusEndpoint.route ~ typesEndpoint.route ~ userEndpoint.route
biSEndpoint.routes ~ lootEndpoint.routes ~ partyEndpoint.routes ~ playerEndpoint.routes ~
statusEndpoint.routes ~ typesEndpoint.routes ~ userEndpoint.routes
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -19,7 +19,7 @@ import me.arcanis.ffxivbis.http.api.v1.json._
@Path("/api/v1")
class StatusEndpoint extends JsonSupport {
def route: Route = getServerStatus
def routes: Route = getServerStatus
@GET
@Path("status")

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -21,7 +21,7 @@ import me.arcanis.ffxivbis.models._
@Path("/api/v1")
class TypesEndpoint(config: Config) extends JsonSupport {
def route: Route = getAllJobs ~ getJobs ~ getPermissions ~ getPieces ~ getPieceTypes ~ getPriority
def routes: Route = getAllJobs ~ getJobs ~ getPermissions ~ getPieces ~ getPieceTypes ~ getPriority
@GET
@Path("types/jobs/all")

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -36,9 +36,9 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
with Authorization
with JsonSupport {
def route: Route = createParty ~ createUser ~ deleteUser ~ getUsers ~ getUsersCurrent
def routes: Route = createParty ~ createUser ~ deleteUser ~ getUsers ~ getUsersCurrent
@PUT
@POST
@Path("party")
@Consumes(value = Array("application/json"))
@Operation(
@ -76,7 +76,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
def createParty: Route =
path("party") {
extractExecutionContext { implicit executionContext =>
put {
post {
entity(as[UserModel]) { user =>
onSuccess(newPartyId) { partyId =>
val admin = user.toUser.copy(partyId = partyId, permission = Permission.admin)
@ -96,7 +96,12 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
summary = "create new user",
description = "Add an user to the specified party",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
requestBody = new RequestBody(
description = "user description",
@ -126,7 +131,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("admin"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("admin"))),
tags = Array("users"),
)
def createUser: Route =
@ -151,7 +156,12 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
summary = "remove user",
description = "Remove an user from the specified party",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
new Parameter(name = "username", in = ParameterIn.PATH, description = "username to remove", example = "siuan"),
),
responses = Array(
@ -172,7 +182,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("admin"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("admin"))),
tags = Array("users"),
)
def deleteUser: Route =
@ -195,7 +205,12 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
summary = "get users",
description = "Return the list of users belong to party",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
responses = Array(
new ApiResponse(
@ -223,7 +238,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("get"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
tags = Array("users"),
)
def getUsers: Route =
@ -246,7 +261,12 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
summary = "get current user",
description = "Return the current user descriptor",
parameters = Array(
new Parameter(name = "partyId", in = ParameterIn.PATH, description = "unique party ID", example = "abcdefgh"),
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
responses = Array(
new ApiResponse(
@ -270,7 +290,7 @@ class UserEndpoint(override val storage: ActorRef[Message], override val auth: A
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic auth", scopes = Array("admin"))),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("admin"))),
tags = Array("users"),
)
def getUsersCurrent: Route =

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -9,5 +9,6 @@
package me.arcanis.ffxivbis.http.api.v1.json
object ApiAction extends Enumeration {
val add, remove = Value
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -16,12 +16,12 @@ import java.time.Instant
trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
private def enumFormat[E <: Enumeration](enum: E): RootJsonFormat[E#Value] =
private def enumFormat[E <: Enumeration](enumeration: E): RootJsonFormat[E#Value] =
new RootJsonFormat[E#Value] {
override def write(obj: E#Value): JsValue = obj.toString.toJson
override def read(json: JsValue): E#Value = json match {
case JsNumber(value) => enum(value.toInt)
case JsString(name) => enum.withName(name)
case JsNumber(value) => enumeration(value.toInt)
case JsString(name) => enumeration.withName(name)
case other => deserializationError(s"String or number expected, got $other")
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,9 +12,11 @@ import io.swagger.v3.oas.annotations.media.Schema
import me.arcanis.ffxivbis.models.PartyDescription
case class PartyDescriptionModel(
@Schema(description = "party id", required = true, example = "abcdefgh") partyId: String,
@Schema(description = "party id", required = true, example = "o3KicHQPW5b0JcOm5yI3") partyId: String,
@Schema(description = "party name") partyAlias: Option[String]
) {
) extends Validator {
require(partyAlias.forall(isValidString), stringMatchError("Party alias"))
def toDescription: PartyDescription = PartyDescription(partyId, partyAlias)
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -10,4 +10,6 @@ package me.arcanis.ffxivbis.http.api.v1.json
import io.swagger.v3.oas.annotations.media.Schema
case class PartyIdModel(@Schema(description = "party id", required = true, example = "abcdefgh") partyId: String)
case class PartyIdModel(
@Schema(description = "party id", required = true, example = "o3KicHQPW5b0JcOm5yI3") partyId: String
)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -17,4 +17,7 @@ case class PlayerBiSLinkModel(
example = "https://ffxiv.ariyala.com/19V5R"
) link: String,
@Schema(description = "player description", required = true) playerId: PlayerIdModel
)
) extends Validator {
require(isValidString(link), stringMatchError("BiS link"))
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,10 +12,14 @@ import io.swagger.v3.oas.annotations.media.Schema
import me.arcanis.ffxivbis.models.{Job, PlayerId}
case class PlayerIdModel(
@Schema(description = "unique party ID. Required in responses", example = "abcdefgh") partyId: Option[String],
@Schema(description = "unique party ID. Required in responses", example = "o3KicHQPW5b0JcOm5yI3") partyId: Option[
String
],
@Schema(description = "job name", required = true, example = "DNC") job: String,
@Schema(description = "player nick name", required = true, example = "Siuan Sanche") nick: String
) {
) extends Validator {
require(isValidString(nick), stringMatchError("Player name"))
def withPartyId(partyId: String): PlayerId =
PlayerId(partyId, Job.withName(job), nick)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,7 +12,7 @@ import io.swagger.v3.oas.annotations.media.Schema
import me.arcanis.ffxivbis.models.PlayerIdWithCounters
case class PlayerIdWithCountersModel(
@Schema(description = "unique party ID", required = true, example = "abcdefgh") partyId: String,
@Schema(description = "unique party ID", required = true, example = "o3KicHQPW5b0JcOm5yI3") partyId: String,
@Schema(description = "job name", required = true, example = "DNC") job: String,
@Schema(description = "player nick name", required = true, example = "Siuan Sanche") nick: String,
@Schema(description = "is piece required by player or not", required = true) isRequired: Boolean,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,16 +12,22 @@ import io.swagger.v3.oas.annotations.media.Schema
import me.arcanis.ffxivbis.models.{BiS, Job, Player}
case class PlayerModel(
@Schema(description = "unique party ID", required = true, example = "abcdefgh") partyId: String,
@Schema(description = "unique party ID", required = true, example = "o3KicHQPW5b0JcOm5yI3") partyId: String,
@Schema(description = "job name", required = true, example = "DNC") job: String,
@Schema(description = "player nick name", required = true, example = "Siuan Sanche") nick: String,
@Schema(description = "pieces in best in slot") bis: Option[Seq[PieceModel]],
@Schema(description = "looted pieces") loot: Option[Seq[LootModel]],
@Schema(description = "link to best in slot", example = "https://ffxiv.ariyala.com/19V5R") link: Option[String],
@Schema(description = "player loot priority", `type` = "number") priority: Option[Int],
@Schema(description = "count of looted pieces which are parts of best in slot") lootCountBiS: Option[Int],
@Schema(
description = "count of looted pieces which are parts of best in slot",
`type` = "number"
) lootCountBiS: Option[Int],
@Schema(description = "total count of looted pieces", `type` = "number") lootCountTotal: Option[Int],
) {
) extends Validator {
require(isValidString(nick), stringMatchError("Player name"))
require(link.forall(isValidString), stringMatchError("BiS link"))
def toPlayer: Player =
Player(

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,23 +12,30 @@ import io.swagger.v3.oas.annotations.media.Schema
import me.arcanis.ffxivbis.models.{Permission, User}
case class UserModel(
@Schema(description = "unique party ID", required = true, example = "abcdefgh") partyId: String,
@Schema(description = "unique party ID", required = true, example = "o3KicHQPW5b0JcOm5yI3") partyId: String,
@Schema(description = "username to login to party", required = true, example = "siuan") username: String,
@Schema(description = "password to login to party", required = true, example = "pa55w0rd") password: String,
@Schema(description = "password to login to party, required for user editing", example = "pa55w0rd") password: Option[
String
],
@Schema(
description = "user permission",
defaultValue = "get",
`type` = "string",
allowableValues = Array("get", "post", "admin")
) permission: Option[Permission.Value] = None
) {
) extends Validator {
require(isValidString(username), stringMatchError("Username"))
require(password.forall(_.nonEmpty), "Password must not be empty")
def toUser: User =
User(partyId, username, password, permission.getOrElse(Permission.get))
password.fold(throw new IllegalArgumentException("Password must noot be empty"))(
User(partyId, username, _, permission.getOrElse(Permission.get))
)
}
object UserModel {
def fromUser(user: User): UserModel =
UserModel(user.partyId, user.username, "", Some(user.permission))
UserModel(user.partyId, user.username, None, Some(user.permission))
}

View File

@ -0,0 +1,17 @@
/*
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.http.api.v1.json
import me.arcanis.ffxivbis.http.ValidatorHelper
trait Validator extends ValidatorHelper {
def stringMatchError(what: String): String =
s"$what must contain only letters or digits or one of (${ValidatorHelper.VALID_CHARACTERS.mkString(", ")})"
}

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.http.api.v2
import me.arcanis.ffxivbis.http.api.v1.{HttpHandler => HttpHandlerV1}
import me.arcanis.ffxivbis.http.api.v2.json.JsonSupport
trait HttpHandler extends HttpHandlerV1 { this: JsonSupport => }

View File

@ -0,0 +1,107 @@
/*
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.http.api.v2
import akka.actor.typed.{ActorRef, Scheduler}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server._
import akka.util.Timeout
import io.swagger.v3.oas.annotations.enums.ParameterIn
import io.swagger.v3.oas.annotations.media.{ArraySchema, Content, Schema}
import io.swagger.v3.oas.annotations.parameters.RequestBody
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import io.swagger.v3.oas.annotations.{Operation, Parameter}
import jakarta.ws.rs._
import me.arcanis.ffxivbis.http.api.v1.json.{ErrorModel, PieceModel, PlayerIdWithCountersModel}
import me.arcanis.ffxivbis.http.api.v2.json._
import me.arcanis.ffxivbis.http.helpers.LootHelper
import me.arcanis.ffxivbis.http.{Authorization, AuthorizationProvider}
import me.arcanis.ffxivbis.messages.Message
@Path("/api/v2")
class LootEndpoint(override val storage: ActorRef[Message], override val auth: AuthorizationProvider)(implicit
timeout: Timeout,
scheduler: Scheduler
) extends LootHelper
with Authorization
with JsonSupport
with HttpHandler {
def routes: Route = suggestLoot
@PUT
@Path("party/{partyId}/loot")
@Consumes(value = Array("application/json"))
@Produces(value = Array("application/json"))
@Operation(
summary = "suggest loot",
description = "Suggest loot pieces to party",
parameters = Array(
new Parameter(
name = "partyId",
in = ParameterIn.PATH,
description = "unique party ID",
example = "o3KicHQPW5b0JcOm5yI3"
),
),
requestBody = new RequestBody(
description = "piece description",
required = true,
content = Array(new Content(schema = new Schema(implementation = classOf[PieceModel])))
),
responses = Array(
new ApiResponse(
responseCode = "200",
description = "Players with counters ordered by priority to get this item",
content = Array(
new Content(
array = new ArraySchema(schema = new Schema(implementation = classOf[PlayerIdWithCountersModel])),
)
)
),
new ApiResponse(
responseCode = "400",
description = "Invalid parameters were supplied",
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
new ApiResponse(
responseCode = "401",
description = "Supplied authorization is invalid",
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
new ApiResponse(
responseCode = "403",
description = "Access is forbidden",
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
new ApiResponse(
responseCode = "500",
description = "Internal server error",
content = Array(new Content(schema = new Schema(implementation = classOf[ErrorModel])))
),
),
security = Array(new SecurityRequirement(name = "basic", scopes = Array("get"))),
tags = Array("loot"),
)
def suggestLoot: Route =
path("party" / Segment / "loot") { partyId =>
extractExecutionContext { implicit executionContext =>
authenticateBasicBCrypt(s"party $partyId", authGet(partyId)) { _ =>
put {
entity(as[PiecesModel]) { piece =>
onSuccess(suggestPiece(partyId, piece.toPiece)) { response =>
complete(response.map(PlayerIdWithCountersModel.fromPlayerId))
}
}
}
}
}
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.http.api.v2
import akka.actor.typed.{ActorRef, Scheduler}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import akka.util.Timeout
import me.arcanis.ffxivbis.http.AuthorizationProvider
import me.arcanis.ffxivbis.http.api.v2.json.JsonSupport
import me.arcanis.ffxivbis.messages.Message
class RootApiV2Endpoint(
storage: ActorRef[Message],
auth: AuthorizationProvider,
)(implicit
timeout: Timeout,
scheduler: Scheduler
) extends JsonSupport
with HttpHandler {
private val lootEndpoint = new LootEndpoint(storage, auth)
def routes: Route =
handleExceptions(exceptionHandler) {
handleRejections(rejectionHandler) {
lootEndpoint.routes
}
}
}

View File

@ -0,0 +1,17 @@
/*
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.http.api.v2.json
import me.arcanis.ffxivbis.http.api.v1.json.{JsonSupport => JsonSupportV1}
import spray.json._
trait JsonSupport extends JsonSupportV1 {
implicit val piecesFormat: RootJsonFormat[PiecesModel] = jsonFormat1(PiecesModel.apply)
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.http.api.v2.json
import io.swagger.v3.oas.annotations.media.Schema
import me.arcanis.ffxivbis.http.api.v1.json.PieceModel
import me.arcanis.ffxivbis.models.Piece
case class PiecesModel(
@Schema(description = "pieces list", required = true) pieces: Seq[PieceModel],
) {
def toPiece: Seq[Piece] = pieces.map(_.toPiece)
}
object PiecesModel {
def fromPiece(pieces: Seq[Piece]): PiecesModel = PiecesModel(pieces.map(PieceModel.fromPiece))
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,7 +12,8 @@ import akka.actor.typed.scaladsl.AskPattern.Askable
import akka.actor.typed.{ActorRef, Scheduler}
import akka.util.Timeout
import me.arcanis.ffxivbis.http.api.v1.json.ApiAction
import me.arcanis.ffxivbis.messages._
import me.arcanis.ffxivbis.messages.DatabaseMessage._
import me.arcanis.ffxivbis.messages.Message
import me.arcanis.ffxivbis.models.{Piece, Player, PlayerId}
import scala.concurrent.{ExecutionContext, Future}
@ -44,13 +45,15 @@ trait BiSHelper extends BisProviderHelper {
timeout: Timeout,
scheduler: Scheduler
): Future[Unit] =
storage.ask(RemovePiecesFromBiS(playerId, _)).flatMap { _ =>
downloadBiS(link, playerId.job)
.flatMap { bis =>
Future.traverse(bis.pieces)(addPieceBiS(playerId, _))
}
.map(_ => ())
}
storage
.ask(RemovePiecesFromBiS(playerId, _))
.flatMap { _ =>
downloadBiS(link, playerId.job)
.flatMap { bis =>
Future.traverse(bis.pieces)(addPieceBiS(playerId, _))
}
}
.flatMap(_ => storage.ask(UpdateBiSLink(playerId, link, _)))
def removePieceBiS(playerId: PlayerId, piece: Piece)(implicit timeout: Timeout, scheduler: Scheduler): Future[Unit] =
storage.ask(RemovePieceFromBiS(playerId, piece, _))

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -11,7 +11,8 @@ package me.arcanis.ffxivbis.http.helpers
import akka.actor.typed.scaladsl.AskPattern.Askable
import akka.actor.typed.{ActorRef, Scheduler}
import akka.util.Timeout
import me.arcanis.ffxivbis.messages.{BiSProviderMessage, DownloadBiS}
import me.arcanis.ffxivbis.messages.BiSProviderMessage
import me.arcanis.ffxivbis.messages.BiSProviderMessage._
import me.arcanis.ffxivbis.models.{BiS, Job}
import scala.concurrent.Future
@ -20,6 +21,6 @@ trait BisProviderHelper {
def provider: ActorRef[BiSProviderMessage]
def downloadBiS(link: String, job: Job.Job)(implicit timeout: Timeout, scheduler: Scheduler): Future[BiS] =
def downloadBiS(link: String, job: Job)(implicit timeout: Timeout, scheduler: Scheduler): Future[BiS] =
provider.ask(DownloadBiS(link, job, _))
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,7 +12,8 @@ import akka.actor.typed.scaladsl.AskPattern.Askable
import akka.actor.typed.{ActorRef, Scheduler}
import akka.util.Timeout
import me.arcanis.ffxivbis.http.api.v1.json.ApiAction
import me.arcanis.ffxivbis.messages._
import me.arcanis.ffxivbis.messages.DatabaseMessage._
import me.arcanis.ffxivbis.messages.Message
import me.arcanis.ffxivbis.models.{Piece, Player, PlayerId, PlayerIdWithCounters}
import scala.concurrent.{ExecutionContext, Future}
@ -55,4 +56,11 @@ trait LootHelper {
scheduler: Scheduler
): Future[Seq[PlayerIdWithCounters]] =
storage.ask(SuggestLoot(partyId, piece, _)).map(_.result)
def suggestPiece(partyId: String, pieces: Seq[Piece])(implicit
executionContext: ExecutionContext,
timeout: Timeout,
scheduler: Scheduler
): Future[Seq[PlayerIdWithCounters]] =
storage.ask(SuggestMultiLoot(partyId, pieces, _)).map(_.result)
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,7 +12,8 @@ import akka.actor.typed.scaladsl.AskPattern.Askable
import akka.actor.typed.{ActorRef, Scheduler}
import akka.util.Timeout
import me.arcanis.ffxivbis.http.api.v1.json.ApiAction
import me.arcanis.ffxivbis.messages._
import me.arcanis.ffxivbis.messages.DatabaseMessage._
import me.arcanis.ffxivbis.messages.Message
import me.arcanis.ffxivbis.models.{PartyDescription, Player, PlayerId}
import scala.concurrent.{ExecutionContext, Future}
@ -26,15 +27,15 @@ trait PlayerHelper extends BisProviderHelper {
)(implicit executionContext: ExecutionContext, timeout: Timeout, scheduler: Scheduler): Future[Unit] =
storage
.ask(ref => AddPlayer(player, ref))
.map { res =>
.map { _ =>
player.link.map(_.trim).filter(_.nonEmpty) match {
case Some(link) =>
downloadBiS(link, player.job)
.map { bis =>
bis.pieces.map(piece => storage.ask(AddPieceToBis(player.playerId, piece, _)))
}
.map(_ => res)
case None => Future.successful(res)
.flatMap(_ => storage.ask(UpdateBiSLink(player.playerId, link, _)))
case None => Future.successful(())
}
}
.flatten

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -11,7 +11,9 @@ package me.arcanis.ffxivbis.http.helpers
import akka.actor.typed.scaladsl.AskPattern.Askable
import akka.actor.typed.{ActorRef, Scheduler}
import akka.util.Timeout
import me.arcanis.ffxivbis.messages._
import me.arcanis.ffxivbis.messages.ControlMessage.GetNewPartyId
import me.arcanis.ffxivbis.messages.DatabaseMessage._
import me.arcanis.ffxivbis.messages.Message
import me.arcanis.ffxivbis.models.User
import scala.concurrent.Future

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -15,7 +15,7 @@ import me.arcanis.ffxivbis.http.{Authorization, AuthorizationProvider}
class RootView(override val auth: AuthorizationProvider) extends Authorization {
def route: Route = getBiS ~ getIndex ~ getLoot ~ getParty ~ getUsers
def routes: Route = getBiS ~ getIndex ~ getLoot ~ getParty ~ getUsers
def getBiS: Route =
path("party" / Segment / "bis") { partyId: String =>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -13,7 +13,10 @@ import me.arcanis.ffxivbis.models.{BiS, Job}
sealed trait BiSProviderMessage
case class DownloadBiS(link: String, job: Job.Job, replyTo: ActorRef[BiS]) extends BiSProviderMessage {
object BiSProviderMessage {
require(link.nonEmpty && link.trim == link, "Link must be not empty and contain no spaces")
case class DownloadBiS(link: String, job: Job, replyTo: ActorRef[BiS]) extends BiSProviderMessage {
require(link.nonEmpty && link.trim == link, "Link must be not empty and contain no spaces")
}
}

View File

@ -1,18 +0,0 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.messages
import akka.actor.typed.ActorRef
import me.arcanis.ffxivbis.models.Party
case class ForgetParty(partyId: String) extends Message
case class GetNewPartyId(replyTo: ActorRef[String]) extends Message
case class StoreParty(partyId: String, party: Party) extends Message

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.messages
import akka.actor.typed.ActorRef
import me.arcanis.ffxivbis.models.Party
sealed trait ControlMessage extends Message
object ControlMessage {
case class ForgetParty(partyId: String) extends ControlMessage
case class GetNewPartyId(replyTo: ActorRef[String]) extends ControlMessage
case class StoreParty(partyId: String, party: Party) extends ControlMessage
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -8,91 +8,129 @@
*/
package me.arcanis.ffxivbis.messages
import akka.actor.typed.{ActorRef, Behavior}
import akka.actor.typed.ActorRef
import me.arcanis.ffxivbis.models._
import me.arcanis.ffxivbis.service.LootSelector
sealed trait DatabaseMessage extends Message {
def partyId: String
def isReadOnly: Boolean
}
object DatabaseMessage {
type Handler = PartialFunction[DatabaseMessage, Behavior[DatabaseMessage]]
// bis handler
trait BisDatabaseMessage extends DatabaseMessage
case class AddPieceToBis(playerId: PlayerId, piece: Piece, replyTo: ActorRef[Unit]) extends BisDatabaseMessage {
override val partyId: String = playerId.partyId
override val isReadOnly: Boolean = false
}
case class GetBiS(partyId: String, playerId: Option[PlayerId], replyTo: ActorRef[Seq[Player]])
extends BisDatabaseMessage {
override val isReadOnly: Boolean = true
}
case class RemovePieceFromBiS(playerId: PlayerId, piece: Piece, replyTo: ActorRef[Unit]) extends BisDatabaseMessage {
override val partyId: String = playerId.partyId
override val isReadOnly: Boolean = false
}
case class RemovePiecesFromBiS(playerId: PlayerId, replyTo: ActorRef[Unit]) extends BisDatabaseMessage {
override val partyId: String = playerId.partyId
override val isReadOnly: Boolean = false
}
// loot handler
trait LootDatabaseMessage extends DatabaseMessage
case class AddPieceTo(playerId: PlayerId, piece: Piece, isFreeLoot: Boolean, replyTo: ActorRef[Unit])
extends LootDatabaseMessage {
override val partyId: String = playerId.partyId
override val isReadOnly: Boolean = false
}
case class GetLoot(partyId: String, playerId: Option[PlayerId], replyTo: ActorRef[Seq[Player]])
extends LootDatabaseMessage {
override val isReadOnly: Boolean = true
}
case class RemovePieceFrom(playerId: PlayerId, piece: Piece, isFreeLoot: Boolean, replyTo: ActorRef[Unit])
extends LootDatabaseMessage {
override val partyId: String = playerId.partyId
override val isReadOnly: Boolean = false
}
case class SuggestLoot(partyId: String, piece: Piece, replyTo: ActorRef[LootSelector.LootSelectorResult])
extends LootDatabaseMessage {
override val isReadOnly: Boolean = true
}
case class SuggestMultiLoot(partyId: String, pieces: Seq[Piece], replyTo: ActorRef[LootSelector.LootSelectorResult])
extends LootDatabaseMessage {
override val isReadOnly: Boolean = true
}
// party handler
trait PartyDatabaseMessage extends DatabaseMessage
case class AddPlayer(player: Player, replyTo: ActorRef[Unit]) extends PartyDatabaseMessage {
override val partyId: String = player.partyId
override val isReadOnly: Boolean = false
}
case class GetParty(partyId: String, replyTo: ActorRef[Party]) extends PartyDatabaseMessage {
override val isReadOnly: Boolean = true
}
case class GetPartyDescription(partyId: String, replyTo: ActorRef[PartyDescription]) extends PartyDatabaseMessage {
override val isReadOnly: Boolean = true
}
case class GetPlayer(playerId: PlayerId, replyTo: ActorRef[Option[Player]]) extends PartyDatabaseMessage {
override val partyId: String = playerId.partyId
override val isReadOnly: Boolean = true
}
case class RemovePlayer(playerId: PlayerId, replyTo: ActorRef[Unit]) extends PartyDatabaseMessage {
override val partyId: String = playerId.partyId
override val isReadOnly: Boolean = false
}
case class UpdateBiSLink(playerId: PlayerId, link: String, actorRef: ActorRef[Unit]) extends PartyDatabaseMessage {
override val partyId: String = playerId.partyId
override val isReadOnly: Boolean = false
}
case class UpdateParty(partyDescription: PartyDescription, replyTo: ActorRef[Unit]) extends PartyDatabaseMessage {
override val partyId: String = partyDescription.partyId
override val isReadOnly: Boolean = false
}
// user handler
trait UserDatabaseMessage extends DatabaseMessage
case class AddUser(user: User, isHashedPassword: Boolean, replyTo: ActorRef[Unit]) extends UserDatabaseMessage {
override val partyId: String = user.partyId
override val isReadOnly: Boolean = false
}
case class DeleteUser(partyId: String, username: String, replyTo: ActorRef[Unit]) extends UserDatabaseMessage {
override val isReadOnly: Boolean = true
}
case class Exists(partyId: String, replyTo: ActorRef[Boolean]) extends UserDatabaseMessage {
override val isReadOnly: Boolean = true
}
case class GetUser(partyId: String, username: String, replyTo: ActorRef[Option[User]]) extends UserDatabaseMessage {
override val isReadOnly: Boolean = true
}
case class GetUsers(partyId: String, replyTo: ActorRef[Seq[User]]) extends UserDatabaseMessage {
override val isReadOnly: Boolean = true
}
}
// bis handler
trait BisDatabaseMessage extends DatabaseMessage
case class AddPieceToBis(playerId: PlayerId, piece: Piece, replyTo: ActorRef[Unit]) extends BisDatabaseMessage {
override def partyId: String = playerId.partyId
}
case class GetBiS(partyId: String, playerId: Option[PlayerId], replyTo: ActorRef[Seq[Player]])
extends BisDatabaseMessage
case class RemovePieceFromBiS(playerId: PlayerId, piece: Piece, replyTo: ActorRef[Unit]) extends BisDatabaseMessage {
override def partyId: String = playerId.partyId
}
case class RemovePiecesFromBiS(playerId: PlayerId, replyTo: ActorRef[Unit]) extends BisDatabaseMessage {
override def partyId: String = playerId.partyId
}
// loot handler
trait LootDatabaseMessage extends DatabaseMessage
case class AddPieceTo(playerId: PlayerId, piece: Piece, isFreeLoot: Boolean, replyTo: ActorRef[Unit])
extends LootDatabaseMessage {
override def partyId: String = playerId.partyId
}
case class GetLoot(partyId: String, playerId: Option[PlayerId], replyTo: ActorRef[Seq[Player]])
extends LootDatabaseMessage
case class RemovePieceFrom(playerId: PlayerId, piece: Piece, isFreeLoot: Boolean, replyTo: ActorRef[Unit])
extends LootDatabaseMessage {
override def partyId: String = playerId.partyId
}
case class SuggestLoot(partyId: String, piece: Piece, replyTo: ActorRef[LootSelector.LootSelectorResult])
extends LootDatabaseMessage
// party handler
trait PartyDatabaseMessage extends DatabaseMessage
case class AddPlayer(player: Player, replyTo: ActorRef[Unit]) extends PartyDatabaseMessage {
override def partyId: String = player.partyId
}
case class GetParty(partyId: String, replyTo: ActorRef[Party]) extends PartyDatabaseMessage
case class GetPartyDescription(partyId: String, replyTo: ActorRef[PartyDescription]) extends PartyDatabaseMessage
case class GetPlayer(playerId: PlayerId, replyTo: ActorRef[Option[Player]]) extends PartyDatabaseMessage {
override def partyId: String = playerId.partyId
}
case class RemovePlayer(playerId: PlayerId, replyTo: ActorRef[Unit]) extends PartyDatabaseMessage {
override def partyId: String = playerId.partyId
}
case class UpdateParty(partyDescription: PartyDescription, replyTo: ActorRef[Unit]) extends PartyDatabaseMessage {
override def partyId: String = partyDescription.partyId
}
// user handler
trait UserDatabaseMessage extends DatabaseMessage
case class AddUser(user: User, isHashedPassword: Boolean, replyTo: ActorRef[Unit]) extends UserDatabaseMessage {
override def partyId: String = user.partyId
}
case class DeleteUser(partyId: String, username: String, replyTo: ActorRef[Unit]) extends UserDatabaseMessage
case class Exists(partyId: String, replyTo: ActorRef[Boolean]) extends UserDatabaseMessage
case class GetUser(partyId: String, username: String, replyTo: ActorRef[Option[User]]) extends UserDatabaseMessage
case class GetUsers(partyId: String, replyTo: ActorRef[Seq[User]]) extends UserDatabaseMessage

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -11,14 +11,14 @@ package me.arcanis.ffxivbis.models
case class BiS(pieces: Seq[Piece]) {
def hasPiece(piece: Piece): Boolean = piece match {
case upgrade: PieceUpgrade => upgrades.contains(upgrade)
case upgrade: Piece.PieceUpgrade => upgrades.contains(upgrade)
case _ => pieces.contains(piece)
}
def upgrades: Map[PieceUpgrade, Int] =
def upgrades: Map[Piece.PieceUpgrade, Int] =
pieces
.groupBy(_.upgrade)
.foldLeft(Map.empty[PieceUpgrade, Int]) {
.foldLeft(Map.empty[Piece.PieceUpgrade, Int]) {
case (acc, (Some(k), v)) => acc + (k -> v.size)
case (acc, _) => acc
}
@ -43,5 +43,5 @@ case class BiS(pieces: Seq[Piece]) {
object BiS {
def empty: BiS = BiS(Seq.empty)
val empty: BiS = BiS(Seq.empty)
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -8,6 +8,26 @@
*/
package me.arcanis.ffxivbis.models
sealed trait Job extends Equals {
def leftSide: Job.LeftSide
def rightSide: Job.RightSide
// conversion to string to avoid recursion
override def canEqual(that: Any): Boolean = that.isInstanceOf[Job]
override def equals(obj: Any): Boolean = {
def equality(objRepr: String): Boolean = objRepr match {
case _ if objRepr == Job.AnyJob.toString => true
case _ if this.toString == Job.AnyJob.toString => true
case _ => this.toString == objRepr
}
canEqual(obj) && equality(obj.toString)
}
}
object Job {
sealed trait RightSide
@ -26,54 +46,38 @@ object Job {
object BodyTanks extends LeftSide
object BodyRanges extends LeftSide
sealed trait Job extends Equals {
def leftSide: LeftSide
def rightSide: RightSide
// conversion to string to avoid recursion
override def canEqual(that: Any): Boolean = that.isInstanceOf[Job]
override def equals(obj: Any): Boolean = {
def equality(objRepr: String): Boolean = objRepr match {
case _ if objRepr == AnyJob.toString => true
case _ if this.toString == AnyJob.toString => true
case _ => this.toString == objRepr
}
canEqual(obj) && equality(obj.toString)
}
}
case object AnyJob extends Job {
val leftSide: LeftSide = null
val rightSide: RightSide = null
override val leftSide: LeftSide = null
override val rightSide: RightSide = null
}
trait Casters extends Job {
val leftSide: LeftSide = BodyCasters
val rightSide: RightSide = AccessoriesInt
override val leftSide: LeftSide = BodyCasters
override val rightSide: RightSide = AccessoriesInt
}
trait Healers extends Job {
val leftSide: LeftSide = BodyHealers
val rightSide: RightSide = AccessoriesMnd
override val leftSide: LeftSide = BodyHealers
override val rightSide: RightSide = AccessoriesMnd
}
trait Mnks extends Job {
val leftSide: LeftSide = BodyMnks
val rightSide: RightSide = AccessoriesStr
override val leftSide: LeftSide = BodyMnks
override val rightSide: RightSide = AccessoriesStr
}
trait Drgs extends Job {
val leftSide: LeftSide = BodyDrgs
val rightSide: RightSide = AccessoriesStr
override val leftSide: LeftSide = BodyDrgs
override val rightSide: RightSide = AccessoriesStr
}
trait Nins extends Job {
override val leftSide: LeftSide = BodyNins
override val rightSide: RightSide = AccessoriesDex
}
trait Tanks extends Job {
val leftSide: LeftSide = BodyTanks
val rightSide: RightSide = AccessoriesVit
override val leftSide: LeftSide = BodyTanks
override val rightSide: RightSide = AccessoriesVit
}
trait Ranges extends Job {
val leftSide: LeftSide = BodyRanges
val rightSide: RightSide = AccessoriesDex
override val leftSide: LeftSide = BodyRanges
override val rightSide: RightSide = AccessoriesDex
}
case object PLD extends Tanks
@ -89,11 +93,9 @@ object Job {
case object MNK extends Mnks
case object DRG extends Drgs
case object RPR extends Drgs
case object NIN extends Job {
val leftSide: LeftSide = BodyNins
val rightSide: RightSide = AccessoriesDex
}
case object NIN extends Nins
case object SAM extends Mnks
case object VPR extends Mnks
case object BRD extends Ranges
case object MCH extends Ranges
@ -102,12 +104,13 @@ object Job {
case object BLM extends Casters
case object SMN extends Casters
case object RDM extends Casters
case object PCT extends Casters
lazy val available: Seq[Job] =
Seq(PLD, WAR, DRK, GNB, WHM, SCH, AST, SGE, MNK, DRG, RPR, NIN, SAM, BRD, MCH, DNC, BLM, SMN, RDM)
lazy val availableWithAnyJob: Seq[Job] = available.prepended(AnyJob)
val available: Seq[Job] =
Seq(PLD, WAR, DRK, GNB, WHM, SCH, AST, SGE, MNK, DRG, RPR, NIN, SAM, VPR, BRD, MCH, DNC, BLM, SMN, RDM, PCT)
val availableWithAnyJob: Seq[Job] = available.prepended(AnyJob)
def withName(job: String): Job.Job =
def withName(job: String): Job =
availableWithAnyJob.find(_.toString.equalsIgnoreCase(job)) match {
case Some(value) => value
case None if job.isEmpty => AnyJob

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,7 +12,5 @@ import java.time.Instant
case class Loot(playerId: Long, piece: Piece, timestamp: Instant, isFreeLoot: Boolean) {
def isFreeLootToString: String = if (isFreeLoot) "yes" else "no"
def isFreeLootToInt: Int = if (isFreeLoot) 1 else 0
lazy val isFreeLootToInt: Int = if (isFreeLoot) 1 else 0
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -14,6 +14,7 @@ import me.arcanis.ffxivbis.service.LootSelector
import scala.jdk.CollectionConverters._
import scala.util.Random
import scala.util.control.NonFatal
case class Party(partyDescription: PartyDescription, rules: Seq[String], players: Map[PlayerId, Player])
extends StrictLogging {
@ -29,13 +30,13 @@ case class Party(partyDescription: PartyDescription, rules: Seq[String], players
require(player.partyId == partyDescription.partyId, "player must belong to this party")
copy(players = players + (player.playerId -> player))
} catch {
case exception: Exception =>
case NonFatal(exception) =>
logger.error("cannot add player", exception)
this
}
def suggestLoot(piece: Piece): LootSelector.LootSelectorResult =
LootSelector(getPlayers, piece, rules)
def suggestLoot(pieces: Seq[Piece]): LootSelector.LootSelectorResult =
LootSelector(getPlayers, pieces, rules)
}
object Party {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -8,10 +8,7 @@
*/
package me.arcanis.ffxivbis.models
case class PartyDescription(partyId: String, partyAlias: Option[String]) {
def alias: String = partyAlias.getOrElse(partyId)
}
case class PartyDescription(partyId: String, partyAlias: Option[String])
object PartyDescription {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -10,20 +10,20 @@ package me.arcanis.ffxivbis.models
sealed trait Piece extends Equals {
def pieceType: PieceType.PieceType
def pieceType: PieceType
def job: Job.Job
def job: Job
def piece: String
def withJob(other: Job.Job): Piece
def withJob(other: Job): Piece
def upgrade: Option[PieceUpgrade] = {
def upgrade: Option[Piece.PieceUpgrade] = {
val isTome = pieceType == PieceType.Tome
Some(this).collect {
case _: PieceAccessory if isTome => AccessoryUpgrade
case _: PieceBody if isTome => BodyUpgrade
case _: PieceWeapon if isTome => WeaponUpgrade
case _: Piece.PieceAccessory if isTome => Piece.AccessoryUpgrade
case _: Piece.PieceBody if isTome => Piece.BodyUpgrade
case _: Piece.PieceWeapon if isTome => Piece.WeaponUpgrade
}
}
@ -31,88 +31,89 @@ sealed trait Piece extends Equals {
def strictEqual(obj: Any): Boolean = equals(obj)
}
trait PieceAccessory extends Piece
trait PieceBody extends Piece
trait PieceUpgrade extends Piece {
val pieceType: PieceType.PieceType = PieceType.Tome
val job: Job.Job = Job.AnyJob
def withJob(other: Job.Job): Piece = this
}
trait PieceWeapon extends Piece
case class Weapon(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceWeapon {
val piece: String = "weapon"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Head(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceBody {
val piece: String = "head"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Body(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceBody {
val piece: String = "body"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Hands(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceBody {
val piece: String = "hands"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Legs(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceBody {
val piece: String = "legs"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Feet(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceBody {
val piece: String = "feet"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Ears(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceAccessory {
val piece: String = "ears"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Neck(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceAccessory {
val piece: String = "neck"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Wrist(override val pieceType: PieceType.PieceType, override val job: Job.Job) extends PieceAccessory {
val piece: String = "wrist"
def withJob(other: Job.Job): Piece = copy(job = other)
}
case class Ring(
override val pieceType: PieceType.PieceType,
override val job: Job.Job,
override val piece: String = "ring"
) extends PieceAccessory {
def withJob(other: Job.Job): Piece = copy(job = other)
override def equals(obj: Any): Boolean = obj match {
case Ring(thatPieceType, thatJob, _) => (thatPieceType == pieceType) && (thatJob == job)
case _ => false
}
override def strictEqual(obj: Any): Boolean = obj match {
case ring: Ring => equals(obj) && (ring.piece == this.piece)
case _ => false
}
}
case object AccessoryUpgrade extends PieceUpgrade {
val piece: String = "accessory upgrade"
}
case object BodyUpgrade extends PieceUpgrade {
val piece: String = "body upgrade"
}
case object WeaponUpgrade extends PieceUpgrade {
val piece: String = "weapon upgrade"
}
object Piece {
def apply(piece: String, pieceType: PieceType.PieceType, job: Job.Job = Job.AnyJob): Piece =
trait PieceAccessory extends Piece
trait PieceBody extends Piece
trait PieceUpgrade extends Piece {
override val pieceType: PieceType = PieceType.Tome
override val job: Job = Job.AnyJob
override def withJob(other: Job): Piece = this
}
trait PieceWeapon extends Piece
case class Weapon(override val pieceType: PieceType, override val job: Job) extends PieceWeapon {
override val piece: String = "weapon"
override def withJob(other: Job): Piece = copy(job = other)
}
case class Head(override val pieceType: PieceType, override val job: Job) extends PieceBody {
override val piece: String = "head"
override def withJob(other: Job): Piece = copy(job = other)
}
case class Body(override val pieceType: PieceType, override val job: Job) extends PieceBody {
override val piece: String = "body"
override def withJob(other: Job): Piece = copy(job = other)
}
case class Hands(override val pieceType: PieceType, override val job: Job) extends PieceBody {
override val piece: String = "hands"
override def withJob(other: Job): Piece = copy(job = other)
}
case class Legs(override val pieceType: PieceType, override val job: Job) extends PieceBody {
override val piece: String = "legs"
override def withJob(other: Job): Piece = copy(job = other)
}
case class Feet(override val pieceType: PieceType, override val job: Job) extends PieceBody {
override val piece: String = "feet"
override def withJob(other: Job): Piece = copy(job = other)
}
case class Ears(override val pieceType: PieceType, override val job: Job) extends PieceAccessory {
override val piece: String = "ears"
override def withJob(other: Job): Piece = copy(job = other)
}
case class Neck(override val pieceType: PieceType, override val job: Job) extends PieceAccessory {
override val piece: String = "neck"
override def withJob(other: Job): Piece = copy(job = other)
}
case class Wrist(override val pieceType: PieceType, override val job: Job) extends PieceAccessory {
override val piece: String = "wrist"
override def withJob(other: Job): Piece = copy(job = other)
}
case class Ring(
override val pieceType: PieceType,
override val job: Job,
override val piece: String = "ring"
) extends PieceAccessory {
override def withJob(other: Job): Piece = copy(job = other)
override def equals(obj: Any): Boolean = obj match {
case Ring(thatPieceType, thatJob, _) => (thatPieceType == pieceType) && (thatJob == job)
case _ => false
}
override def strictEqual(obj: Any): Boolean = obj match {
case ring: Ring => equals(obj) && (ring.piece == this.piece)
case _ => false
}
}
case object AccessoryUpgrade extends PieceUpgrade {
override val piece: String = "accessory upgrade"
}
case object BodyUpgrade extends PieceUpgrade {
override val piece: String = "body upgrade"
}
case object WeaponUpgrade extends PieceUpgrade {
override val piece: String = "weapon upgrade"
}
def apply(piece: String, pieceType: PieceType, job: Job = Job.AnyJob): Piece =
piece.toLowerCase match {
case "weapon" => Weapon(pieceType, job)
case "head" => Head(pieceType, job)
case "body" => Body(pieceType, job)
case "hands" => Hands(pieceType, job)
case "hand" | "hands" => Hands(pieceType, job)
case "legs" => Legs(pieceType, job)
case "feet" => Feet(pieceType, job)
case "ears" => Ears(pieceType, job)
@ -125,7 +126,7 @@ object Piece {
case other => throw new Error(s"Unknown item type $other")
}
lazy val available: Seq[String] = Seq(
val available: Seq[String] = Seq(
"weapon",
"head",
"body",

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -8,17 +8,16 @@
*/
package me.arcanis.ffxivbis.models
sealed trait PieceType
object PieceType {
sealed trait PieceType
case object Crafted extends PieceType
case object Tome extends PieceType
case object Savage extends PieceType
case object Tome extends PieceType
case object Crafted extends PieceType
case object Artifact extends PieceType
lazy val available: Seq[PieceType] =
Seq(Crafted, Tome, Savage, Artifact)
val available: Seq[PieceType] = Seq(Savage, Tome, Crafted, Artifact)
def withName(pieceType: String): PieceType =
available.find(_.toString.equalsIgnoreCase(pieceType)) match {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -11,7 +11,7 @@ package me.arcanis.ffxivbis.models
case class Player(
id: Long,
partyId: String,
job: Job.Job,
job: Job,
nick: String,
bis: BiS,
loot: Seq[Loot],
@ -51,7 +51,7 @@ case class Player(
piece match {
case None => false
case Some(p) if !bis.hasPiece(p) => false
case Some(p: PieceUpgrade) => bis.upgrades(p) > lootCount(piece)
case Some(p: Piece.PieceUpgrade) => bis.upgrades(p) > lootCount(piece)
case Some(_) => lootCount(piece) == 0
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -13,14 +13,14 @@ import scala.util.matching.Regex
trait PlayerIdBase {
def job: Job.Job
def job: Job
def nick: String
override def toString: String = s"$nick ($job)"
}
case class PlayerId(partyId: String, job: Job.Job, nick: String) extends PlayerIdBase
case class PlayerId(partyId: String, job: Job, nick: String) extends PlayerIdBase
object PlayerId {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -10,7 +10,7 @@ package me.arcanis.ffxivbis.models
case class PlayerIdWithCounters(
partyId: String,
job: Job.Job,
job: Job,
nick: String,
isRequired: Boolean,
priority: Int,
@ -24,8 +24,6 @@ case class PlayerIdWithCounters(
def gt(that: PlayerIdWithCounters, orderBy: Seq[String]): Boolean =
withCounters(orderBy) > that.withCounters(orderBy)
def isRequiredToString: String = if (isRequired) "yes" else "no"
def playerId: PlayerId = PlayerId(partyId, job, nick)
private val counters: Map[String, Int] = Map(
@ -47,13 +45,13 @@ object PlayerIdWithCounters {
def >(that: PlayerCountersComparator): Boolean = {
@scala.annotation.tailrec
def compareLists(left: List[Int], right: List[Int]): Boolean =
def compare(left: Seq[Int], right: Seq[Int]): Boolean =
(left, right) match {
case (hl :: tl, hr :: tr) => if (hl == hr) compareLists(tl, tr) else hl > hr
case (hl :: tl, hr :: tr) => if (hl == hr) compare(tl, tr) else hl > hr
case (_ :: _, Nil) => true
case (_, _) => false
}
compareLists(values.toList, that.values.toList)
compare(values, that.values)
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -11,6 +11,7 @@ package me.arcanis.ffxivbis.models
import org.mindrot.jbcrypt.BCrypt
object Permission extends Enumeration {
val get, post, admin = Value
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -10,9 +10,9 @@ package me.arcanis.ffxivbis.service
import me.arcanis.ffxivbis.models.{Piece, Player, PlayerIdWithCounters}
class LootSelector(players: Seq[Player], piece: Piece, orderBy: Seq[String]) {
class LootSelector(players: Seq[Player], pieces: Seq[Piece], orderBy: Seq[String]) {
val counters: Seq[PlayerIdWithCounters] = players.map(_.withCounters(Some(piece)))
val counters: Seq[PlayerIdWithCounters] = pieces.flatMap(piece => players.map(_.withCounters(Some(piece))))
def suggest: LootSelector.LootSelectorResult =
LootSelector.LootSelectorResult {
@ -22,8 +22,8 @@ class LootSelector(players: Seq[Player], piece: Piece, orderBy: Seq[String]) {
object LootSelector {
def apply(players: Seq[Player], piece: Piece, orderBy: Seq[String]): LootSelectorResult =
new LootSelector(players, piece, orderBy).suggest
def apply(players: Seq[Player], pieces: Seq[Piece], orderBy: Seq[String]): LootSelectorResult =
new LootSelector(players, pieces, orderBy).suggest
case class LootSelectorResult(result: Seq[PlayerIdWithCounters])
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -16,7 +16,6 @@ import com.typesafe.scalalogging.StrictLogging
import me.arcanis.ffxivbis.messages._
import me.arcanis.ffxivbis.models.Party
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ExecutionContext, Future}
class PartyService(context: ActorContext[Message], storage: ActorRef[DatabaseMessage])
@ -37,23 +36,24 @@ class PartyService(context: ActorContext[Message], storage: ActorRef[DatabaseMes
override def onMessage(msg: Message): Behavior[Message] = handle(Map.empty)(msg)
private def handle(cache: Map[String, Party]): Message.Handler = {
case ForgetParty(partyId) =>
case ControlMessage.ForgetParty(partyId) =>
Behaviors.receiveMessage(handle(cache - partyId))
case GetNewPartyId(client) =>
case ControlMessage.GetNewPartyId(client) =>
getPartyId.foreach(client ! _)
Behaviors.same
case StoreParty(partyId, party) =>
case ControlMessage.StoreParty(partyId, party) =>
Behaviors.receiveMessage(handle(cache.updated(partyId, party)))
case GetParty(partyId, client) =>
case DatabaseMessage.GetParty(partyId, client) =>
val party = cache.get(partyId) match {
case Some(party) => Future.successful(party)
case None =>
storage.ask(ref => GetParty(partyId, ref)).map { party =>
context.self ! StoreParty(partyId, party)
context.system.scheduler.scheduleOnce(cacheTimeout, () => context.self ! ForgetParty(partyId))
storage.ask(ref => DatabaseMessage.GetParty(partyId, ref)).map { party =>
context.self ! ControlMessage.StoreParty(partyId, party)
context.system.scheduler
.scheduleOnce(cacheTimeout, () => context.self ! ControlMessage.ForgetParty(partyId))
party
}
}
@ -62,12 +62,13 @@ class PartyService(context: ActorContext[Message], storage: ActorRef[DatabaseMes
case req: DatabaseMessage =>
storage ! req
Behaviors.receiveMessage(handle(cache - req.partyId))
val result = if (req.isReadOnly) cache else cache - req.partyId
Behaviors.receiveMessage(handle(result))
}
private def getPartyId: Future[String] = {
val partyId = Party.randomPartyId
storage.ask(ref => Exists(partyId, ref)).flatMap {
storage.ask(ref => DatabaseMessage.Exists(partyId, ref)).flatMap {
case true => getPartyId
case false => Future.successful(partyId)
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -13,14 +13,15 @@ import akka.actor.typed.scaladsl.{AbstractBehavior, ActorContext, Behaviors}
import akka.actor.typed.{Behavior, PostStop, Signal}
import akka.http.scaladsl.model._
import com.typesafe.scalalogging.StrictLogging
import me.arcanis.ffxivbis.messages.{BiSProviderMessage, DownloadBiS}
import me.arcanis.ffxivbis.messages.BiSProviderMessage
import me.arcanis.ffxivbis.models.{BiS, Job, Piece, PieceType}
import me.arcanis.ffxivbis.service.bis.parser.Parser
import me.arcanis.ffxivbis.service.bis.parser.impl.{Ariyala, Etro}
import me.arcanis.ffxivbis.service.bis.parser.impl.{Ariyala, Etro, XIVGear}
import spray.json._
import java.nio.file.Paths
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal
import scala.util.{Failure, Success}
class BisProvider(context: ActorContext[BiSProviderMessage])
@ -32,7 +33,7 @@ class BisProvider(context: ActorContext[BiSProviderMessage])
override def onMessage(msg: BiSProviderMessage): Behavior[BiSProviderMessage] =
msg match {
case DownloadBiS(link, job, client) =>
case BiSProviderMessage.DownloadBiS(link, job, client) =>
get(link, job).onComplete {
case Success(items) => client ! BiS(items)
case Failure(exception) =>
@ -46,16 +47,19 @@ class BisProvider(context: ActorContext[BiSProviderMessage])
Behaviors.same
}
private def get(link: String, job: Job.Job): Future[Seq[Piece]] =
private def get(link: String, job: Job): Future[Seq[Piece]] =
try {
val url = Uri(link)
val id = Paths.get(link).normalize.getFileName.toString
val parser = if (url.authority.host.address().contains("etro")) Etro else Ariyala
val parser =
if (url.authority.host.address().contains("etro")) Etro
else if (url.authority.host.address().contains("xivgear.app")) XIVGear
else Ariyala
val uri = parser.uri(url, id)
sendRequest(uri, BisProvider.parseBisJsonToPieces(job, parser, getPieceType))
} catch {
case exception: Exception => Future.failed(exception)
case NonFatal(exception) => Future.failed(exception)
}
}
@ -65,9 +69,9 @@ object BisProvider {
Behaviors.setup[BiSProviderMessage](context => new BisProvider(context))
private def parseBisJsonToPieces(
job: Job.Job,
job: Job,
idParser: Parser,
pieceTypes: Seq[Long] => Future[Map[Long, PieceType.PieceType]]
pieceTypes: Seq[Long] => Future[Map[Long, PieceType]]
)(js: JsObject)(implicit executionContext: ExecutionContext): Future[Seq[Piece]] =
idParser.parse(job, js).flatMap { pieces =>
pieceTypes(pieces.values.toSeq).map { types =>
@ -80,12 +84,11 @@ object BisProvider {
}
}
def remapKey(key: String): Option[String] = key match {
case "mainhand" => Some("weapon")
case "chest" => Some("body")
case "ringLeft" | "fingerL" => Some("left ring")
case "ringRight" | "fingerR" => Some("right ring")
case "weapon" | "head" | "body" | "hands" | "legs" | "feet" | "ears" | "neck" | "wrist" | "wrists" => Some(key)
case _ => None
def remapKey(key: String): Option[String] = Some(key.toLowerCase).collect {
case "mainhand" => "weapon"
case "chest" => "body"
case "ringleft" | "fingerl" => "left ring"
case "ringright" | "fingerr" => "right ring"
case "weapon" | "head" | "body" | "hand" | "hands" | "legs" | "feet" | "ears" | "neck" | "wrist" | "wrists" => key
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -22,7 +22,7 @@ trait XivApi extends RequestExecutor {
private val xivapiUrl = config.getString("me.arcanis.ffxivbis.bis-provider.xivapi-url")
private val xivapiKey = Try(config.getString("me.arcanis.ffxivbis.bis-provider.xivapi-key")).toOption
private val preloadedItems: Map[Long, PieceType.PieceType] =
private val preloadedItems: Map[Long, PieceType] =
config
.getConfigList("me.arcanis.ffxivbis.bis-provider.cached-items")
.asScala
@ -31,112 +31,48 @@ trait XivApi extends RequestExecutor {
}
.toMap
def getPieceType(itemIds: Seq[Long]): Future[Map[Long, PieceType.PieceType]] = {
val (local, remote) = itemIds.foldLeft((Map.empty[Long, PieceType.PieceType], Seq.empty[Long])) {
case ((l, r), id) =>
if (preloadedItems.contains(id)) (l.updated(id, preloadedItems(id)), r)
else (l, r :+ id)
def getPieceType(itemIds: Seq[Long]): Future[Map[Long, PieceType]] = {
val (local, remote) = itemIds.foldLeft((Map.empty[Long, PieceType], Seq.empty[Long])) { case ((l, r), id) =>
if (preloadedItems.contains(id)) (l.updated(id, preloadedItems(id)), r)
else (l, r :+ id)
}
if (remote.isEmpty) Future.successful(local)
else remotePieceType(remote).map(_ ++ local)
}
private def remotePieceType(itemIds: Seq[Long]): Future[Map[Long, PieceType.PieceType]] = {
val uriForItems = Uri(xivapiUrl)
.withPath(Uri.Path / "item")
.withQuery(
Uri.Query(
Map(
"columns" -> Seq("ID", "GameContentLinks").mkString(","),
"ids" -> itemIds.mkString(","),
"private_key" -> xivapiKey.getOrElse("")
)
)
)
sendRequest(uriForItems, XivApi.parseXivapiJsonToShop).flatMap { shops =>
val shopIds = shops.values.map(_._2).toSet
val columns = shops.values.map(pair => s"ItemCost${pair._1}").toSet
val uriForShops = Uri(xivapiUrl)
.withPath(Uri.Path / "specialshop")
.withQuery(
Uri.Query(
Map(
"columns" -> (columns + "ID").mkString(","),
"ids" -> shopIds.mkString(","),
"private_key" -> xivapiKey.getOrElse("")
private def remotePieceType(itemIds: Seq[Long]): Future[Map[Long, PieceType]] =
Future
.traverse(itemIds) { id =>
val uriForItem = Uri(xivapiUrl)
.withPath(Uri.Path / "api" / "sheet" / "Item" / id.toString)
.withQuery(
Uri.Query(
Map(
"fields" -> Seq("Lot").mkString(","),
"private_key" -> xivapiKey.getOrElse("")
)
)
)
)
sendRequest(uriForShops, XivApi.parseXivapiJsonToType(shops))
}
}
sendRequest(uriForItem, XivApi.parseXivapiJsonToLot).map(id -> _)
}
.map(_.toMap)
}
object XivApi {
private def parseXivapiJsonToShop(
js: JsObject
)(implicit executionContext: ExecutionContext): Future[Map[Long, (String, Long)]] = {
def extractTraderId(js: JsObject) =
js.fields
.get("Recipe")
.map(_ => "crafted" -> -1L) // you can craft this item
.orElse { // lets try shop items
js.fields("SpecialShop").asJsObject.fields.collectFirst {
case (shopName, JsArray(array)) if shopName.startsWith("ItemReceive") =>
val shopId = array.head match {
case JsNumber(id) => id.toLong
case other => throw deserializationError(s"Could not parse $other")
}
shopName.replace("ItemReceive", "") -> shopId
}
}
.getOrElse(throw deserializationError(s"Could not parse $js"))
private def parseXivapiJsonToLot(js: JsObject)(implicit executionContext: ExecutionContext): Future[PieceType] =
Future {
js.fields("Results") match {
case array: JsArray =>
array.elements
.map(_.asJsObject.getFields("ID", "GameContentLinks") match {
case Seq(JsNumber(id), shop: JsObject) => id.toLong -> extractTraderId(shop.asJsObject)
case other => throw deserializationError(s"Could not parse $other")
})
.toMap
case other => throw deserializationError(s"Could not parse $other")
}
}
}
private def parseXivapiJsonToType(
shops: Map[Long, (String, Long)]
)(js: JsObject)(implicit executionContext: ExecutionContext): Future[Map[Long, PieceType.PieceType]] =
Future {
val shopMap = js.fields("Results") match {
case array: JsArray =>
array.elements.collect { case shop: JsObject =>
shop.fields("ID") match {
case JsNumber(id) => id.toLong -> shop
case other => throw deserializationError(s"Could not parse $other")
js.fields("fields") match {
case JsObject(fields) =>
fields
.get("Lot")
.collect {
case JsBoolean(true) => PieceType.Savage
case JsBoolean(false) => PieceType.Tome
}
}.toMap
case other => throw deserializationError(s"Could not parse $other")
}
shops.map { case (itemId, (index, shopId)) =>
val pieceType =
if (index == "crafted" && shopId == -1L) PieceType.Crafted
else
Try(shopMap(shopId).fields(s"ItemCost$index").asJsObject)
.getOrElse(throw new Exception(s"${shopMap(shopId).fields(s"ItemCost$index")}, $index"))
.getFields("IsUnique", "StackSize") match {
case Seq(JsNumber(isUnique), JsNumber(stackSize)) =>
if (isUnique == 1 || stackSize.toLong != 999) PieceType.Tome // either upgraded gear or tomes found
else PieceType.Savage
case other => throw deserializationError(s"Could not parse $other")
}
itemId -> pieceType
.getOrElse(throw deserializationError(s"Could not find lot field in $fields"))
case other => throw deserializationError(s"Could not read fields as object from $other")
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -17,7 +17,7 @@ import scala.concurrent.{ExecutionContext, Future}
trait Parser extends StrictLogging {
def parse(job: Job.Job, js: JsObject)(implicit executionContext: ExecutionContext): Future[Map[String, Long]]
def parse(job: Job, js: JsObject)(implicit executionContext: ExecutionContext): Future[Map[String, Long]]
def uri(root: Uri, id: String): Uri
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -18,7 +18,7 @@ import scala.concurrent.{ExecutionContext, Future}
object Ariyala extends Parser {
override def parse(job: Job.Job, js: JsObject)(implicit
override def parse(job: Job, js: JsObject)(implicit
executionContext: ExecutionContext
): Future[Map[String, Long]] =
Future {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -18,7 +18,7 @@ import scala.concurrent.{ExecutionContext, Future}
object Etro extends Parser {
override def parse(job: Job.Job, js: JsObject)(implicit
override def parse(job: Job, js: JsObject)(implicit
executionContext: ExecutionContext
): Future[Map[String, Long]] =
Future {

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
*
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause
*/
package me.arcanis.ffxivbis.service.bis.parser.impl
import akka.http.scaladsl.model.Uri
import me.arcanis.ffxivbis.models.Job
import me.arcanis.ffxivbis.service.bis.BisProvider
import me.arcanis.ffxivbis.service.bis.parser.Parser
import spray.json.{deserializationError, JsNumber, JsObject}
import scala.concurrent.{ExecutionContext, Future}
object XIVGear extends Parser {
override def parse(job: Job, js: JsObject)(implicit executionContext: ExecutionContext): Future[Map[String, Long]] =
Future {
val set = js.fields.get("items") match {
case Some(JsObject(items)) => items
case other => throw deserializationError(s"Invalid job name $other")
}
set.foldLeft(Map.empty[String, Long]) {
case (acc, (key, JsObject(properties))) =>
val pieceId = properties.get("id").collect { case JsNumber(id) =>
id.toLong
}
(for (
piece <- BisProvider.remapKey(key);
id <- pieceId
) yield (piece, id)).map(acc + _).getOrElse(acc)
case (acc, _) => acc
}
}
override def uri(root: Uri, id: String): Uri = {
val gearSet = Uri(id).query().get("page").map(_.replace("sl|", "")).getOrElse(id)
root.withHost(s"api.${root.authority.host.address()}").withPath(Uri.Path / "shortlink" / gearSet)
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -8,30 +8,33 @@
*/
package me.arcanis.ffxivbis.service.database.impl
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
import me.arcanis.ffxivbis.messages._
import me.arcanis.ffxivbis.messages.DatabaseMessage
import me.arcanis.ffxivbis.messages.DatabaseMessage._
import me.arcanis.ffxivbis.service.database.Database
trait DatabaseBiSHandler { this: Database =>
def bisHandler: DatabaseMessage.Handler = {
case AddPieceToBis(playerId, piece, client) =>
run(profile.insertPieceBiS(playerId, piece))(_ => client ! ())
Behaviors.same
def bisHandler(msg: BisDatabaseMessage): Behavior[DatabaseMessage] =
msg match {
case AddPieceToBis(playerId, piece, client) =>
run(profile.insertPieceBiS(playerId, piece))(_ => client ! ())
Behaviors.same
case GetBiS(partyId, maybePlayerId, client) =>
run {
getParty(partyId, withBiS = true, withLoot = false)
.map(filterParty(_, maybePlayerId))
}(client ! _)
Behaviors.same
case GetBiS(partyId, maybePlayerId, client) =>
run {
getParty(partyId, withBiS = true, withLoot = false)
.map(filterParty(_, maybePlayerId))
}(client ! _)
Behaviors.same
case RemovePieceFromBiS(playerId, piece, client) =>
run(profile.deletePieceBiS(playerId, piece))(_ => client ! ())
Behaviors.same
case RemovePieceFromBiS(playerId, piece, client) =>
run(profile.deletePieceBiS(playerId, piece))(_ => client ! ())
Behaviors.same
case RemovePiecesFromBiS(playerId, client) =>
run(profile.deletePiecesBiS(playerId))(_ => client ! ())
Behaviors.same
}
case RemovePiecesFromBiS(playerId, client) =>
run(profile.deletePiecesBiS(playerId))(_ => client ! ())
Behaviors.same
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -12,6 +12,7 @@ import akka.actor.typed.scaladsl.{AbstractBehavior, ActorContext}
import akka.actor.typed.{Behavior, DispatcherSelector}
import com.typesafe.config.Config
import me.arcanis.ffxivbis.messages.DatabaseMessage
import me.arcanis.ffxivbis.messages.DatabaseMessage.{BisDatabaseMessage, LootDatabaseMessage, PartyDatabaseMessage, UserDatabaseMessage}
import me.arcanis.ffxivbis.service.database.Database
import me.arcanis.ffxivbis.storage.DatabaseProfile
@ -32,8 +33,12 @@ class DatabaseImpl(context: ActorContext[DatabaseMessage])
override val config: Config = context.system.settings.config
override val profile: DatabaseProfile = new DatabaseProfile(executionContext, config)
override def onMessage(msg: DatabaseMessage): Behavior[DatabaseMessage] = handle(msg)
override def onMessage(msg: DatabaseMessage): Behavior[DatabaseMessage] =
msg match {
case msg: BisDatabaseMessage => bisHandler(msg)
case msg: LootDatabaseMessage => lootHandler(msg)
case msg: PartyDatabaseMessage => partyHandler(msg)
case msg: UserDatabaseMessage => userHandler(msg)
}
private def handle: DatabaseMessage.Handler =
bisHandler.orElse(lootHandler).orElse(partyHandler).orElse(userHandler)
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -8,8 +8,10 @@
*/
package me.arcanis.ffxivbis.service.database.impl
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
import me.arcanis.ffxivbis.messages._
import me.arcanis.ffxivbis.messages.DatabaseMessage
import me.arcanis.ffxivbis.messages.DatabaseMessage._
import me.arcanis.ffxivbis.models.Loot
import me.arcanis.ffxivbis.service.database.Database
@ -17,28 +19,36 @@ import java.time.Instant
trait DatabaseLootHandler { this: Database =>
def lootHandler: DatabaseMessage.Handler = {
case AddPieceTo(playerId, piece, isFreeLoot, client) =>
val loot = Loot(-1, piece, Instant.now, isFreeLoot)
run(profile.insertPiece(playerId, loot))(_ => client ! ())
Behaviors.same
def lootHandler(msg: LootDatabaseMessage): Behavior[DatabaseMessage] =
msg match {
case AddPieceTo(playerId, piece, isFreeLoot, client) =>
val loot = Loot(-1, piece, Instant.now, isFreeLoot)
run(profile.insertPiece(playerId, loot))(_ => client ! ())
Behaviors.same
case GetLoot(partyId, maybePlayerId, client) =>
run {
getParty(partyId, withBiS = false, withLoot = true)
.map(filterParty(_, maybePlayerId))
}(client ! _)
Behaviors.same
case GetLoot(partyId, maybePlayerId, client) =>
run {
getParty(partyId, withBiS = false, withLoot = true)
.map(filterParty(_, maybePlayerId))
}(client ! _)
Behaviors.same
case RemovePieceFrom(playerId, piece, isFreeLoot, client) =>
run(profile.deletePiece(playerId, piece, isFreeLoot))(_ => client ! ())
Behaviors.same
case RemovePieceFrom(playerId, piece, isFreeLoot, client) =>
run(profile.deletePiece(playerId, piece, isFreeLoot))(_ => client ! ())
Behaviors.same
case SuggestLoot(partyId, piece, client) =>
run {
getParty(partyId, withBiS = true, withLoot = true)
.map(_.suggestLoot(piece))
}(client ! _)
Behaviors.same
}
case SuggestLoot(partyId, piece, client) =>
run {
getParty(partyId, withBiS = true, withLoot = true)
.map(_.suggestLoot(Seq(piece)))
}(client ! _)
Behaviors.same
case SuggestMultiLoot(partyId, pieces, client) =>
run {
getParty(partyId, withBiS = true, withLoot = true)
.map(_.suggestLoot(pieces))
}(client ! _)
Behaviors.same
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -8,8 +8,10 @@
*/
package me.arcanis.ffxivbis.service.database.impl
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
import me.arcanis.ffxivbis.messages._
import me.arcanis.ffxivbis.messages.DatabaseMessage
import me.arcanis.ffxivbis.messages.DatabaseMessage._
import me.arcanis.ffxivbis.models.{BiS, Player}
import me.arcanis.ffxivbis.service.database.Database
@ -17,50 +19,55 @@ import scala.concurrent.Future
trait DatabasePartyHandler { this: Database =>
def partyHandler: DatabaseMessage.Handler = {
case AddPlayer(player, client) =>
run(profile.insertPlayer(player))(_ => client ! ())
Behaviors.same
def partyHandler(msg: PartyDatabaseMessage): Behavior[DatabaseMessage] =
msg match {
case AddPlayer(player, client) =>
run(profile.insertPlayer(player))(_ => client ! ())
Behaviors.same
case GetParty(partyId, client) =>
run(getParty(partyId, withBiS = true, withLoot = true))(client ! _)
Behaviors.same
case GetParty(partyId, client) =>
run(getParty(partyId, withBiS = true, withLoot = true))(client ! _)
Behaviors.same
case GetPartyDescription(partyId, client) =>
run(profile.getPartyDescription(partyId))(client ! _)
Behaviors.same
case GetPartyDescription(partyId, client) =>
run(profile.getPartyDescription(partyId))(client ! _)
Behaviors.same
case GetPlayer(playerId, client) =>
run {
profile
.getPlayerFull(playerId)
.flatMap { maybePlayerData =>
Future.traverse(maybePlayerData.toSeq) { playerData =>
for {
bis <- profile.getPiecesBiS(playerId)
loot <- profile.getPieces(playerId)
} yield Player(
playerData.id,
playerId.partyId,
playerId.job,
playerId.nick,
BiS(bis.map(_.piece)),
loot,
playerData.link,
playerData.priority
)
case GetPlayer(playerId, client) =>
run {
profile
.getPlayerFull(playerId)
.flatMap { maybePlayerData =>
Future.traverse(maybePlayerData.toSeq) { playerData =>
for {
bis <- profile.getPiecesBiS(playerId)
loot <- profile.getPieces(playerId)
} yield Player(
playerData.id,
playerId.partyId,
playerId.job,
playerId.nick,
BiS(bis.map(_.piece)),
loot,
playerData.link,
playerData.priority
)
}
}
}
.map(_.headOption)
}(client ! _)
Behaviors.same
.map(_.headOption)
}(client ! _)
Behaviors.same
case RemovePlayer(playerId, client) =>
run(profile.deletePlayer(playerId))(_ => client ! ())
Behaviors.same
case RemovePlayer(playerId, client) =>
run(profile.deletePlayer(playerId))(_ => client ! ())
Behaviors.same
case UpdateParty(description, client) =>
run(profile.insertPartyDescription(description))(_ => client ! ())
Behaviors.same
}
case UpdateBiSLink(playerId, link, client) =>
run(profile.updateBiSLink(playerId, link))(_ => client ! ())
Behaviors.same
case UpdateParty(description, client) =>
run(profile.insertPartyDescription(description))(_ => client ! ())
Behaviors.same
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -8,32 +8,35 @@
*/
package me.arcanis.ffxivbis.service.database.impl
import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
import me.arcanis.ffxivbis.messages._
import me.arcanis.ffxivbis.messages.DatabaseMessage
import me.arcanis.ffxivbis.messages.DatabaseMessage._
import me.arcanis.ffxivbis.service.database.Database
trait DatabaseUserHandler { this: Database =>
def userHandler: DatabaseMessage.Handler = {
case AddUser(user, isHashedPassword, client) =>
val toInsert = if (isHashedPassword) user else user.withHashedPassword
run(profile.insertUser(toInsert))(_ => client ! ())
Behaviors.same
def userHandler(msg: UserDatabaseMessage): Behavior[DatabaseMessage] =
msg match {
case AddUser(user, isHashedPassword, client) =>
val toInsert = if (isHashedPassword) user else user.withHashedPassword
run(profile.insertUser(toInsert))(_ => client ! ())
Behaviors.same
case DeleteUser(partyId, username, client) =>
run(profile.deleteUser(partyId, username))(_ => client ! ())
Behaviors.same
case DeleteUser(partyId, username, client) =>
run(profile.deleteUser(partyId, username))(_ => client ! ())
Behaviors.same
case Exists(partyId, client) =>
run(profile.exists(partyId))(client ! _)
Behaviors.same
case Exists(partyId, client) =>
run(profile.exists(partyId))(client ! _)
Behaviors.same
case GetUser(partyId, username, client) =>
run(profile.getUser(partyId, username))(client ! _)
Behaviors.same
case GetUser(partyId, username, client) =>
run(profile.getUser(partyId, username))(client ! _)
Behaviors.same
case GetUsers(partyId, client) =>
run(profile.getUsers(partyId))(client ! _)
Behaviors.same
}
case GetUsers(partyId, client) =>
run(profile.getUsers(partyId))(client ! _)
Behaviors.same
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -53,12 +53,14 @@ trait BiSProfile extends DatabaseConnection {
def getPiecesBiSById(playerId: Long): Future[Seq[Loot]] = getPiecesBiSById(Seq(playerId))
def getPiecesBiSById(playerIds: Seq[Long]): Future[Seq[Loot]] =
withConnection { implicit conn =>
SQL("""select * from bis where player_id in ({player_ids})""")
.on("player_ids" -> playerIds)
.executeQuery()
.as(loot.*)
}
if (playerIds.isEmpty) Future.successful(Seq.empty)
else
withConnection { implicit conn =>
SQL("""select * from bis where player_id in ({player_ids})""")
.on("player_ids" -> playerIds)
.executeQuery()
.as(loot.*)
}
def insertPieceBiSById(piece: Piece)(playerId: Long): Future[Int] =
withConnection { implicit conn =>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -16,6 +16,7 @@ import me.arcanis.ffxivbis.models.{Loot, Piece, PlayerId}
import java.time.Instant
import javax.sql.DataSource
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal
class DatabaseProfile(override val executionContext: ExecutionContext, config: Config)
extends StrictLogging
@ -31,7 +32,7 @@ class DatabaseProfile(override val executionContext: ExecutionContext, config: C
val dataSourceConfig = DatabaseConnection.getDataSourceConfig(profile)
new HikariDataSource(dataSourceConfig)
} catch {
case exception: Exception =>
case NonFatal(exception) =>
logger.error("exception during storage initialization", exception)
throw exception
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).
@ -59,12 +59,14 @@ trait LootProfile extends DatabaseConnection {
def getPiecesById(playerId: Long): Future[Seq[Loot]] = getPiecesById(Seq(playerId))
def getPiecesById(playerIds: Seq[Long]): Future[Seq[Loot]] =
withConnection { implicit conn =>
SQL("""select * from loot where player_id in ({player_ids})""")
.on("player_ids" -> playerIds)
.executeQuery()
.as(loot.*)
}
if (playerIds.isEmpty) Future.successful(Seq.empty)
else
withConnection { implicit conn =>
SQL("""select * from loot where player_id in ({player_ids})""")
.on("player_ids" -> playerIds)
.executeQuery()
.as(loot.*)
}
def insertPieceById(loot: Loot)(playerId: Long): Future[Int] =
withConnection { implicit conn =>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Evgeniy Alekseev.
* Copyright (c) 2021-2026 Evgeniy Alekseev.
*
* This file is part of ffxivbis
* (see https://github.com/arcan1s/ffxivbis).

Some files were not shown because too many files have changed in this diff Show More