loottracker: submit loot when not logged in
This is to aid the wiki drop log project. The data is not otherwise stored.
This commit is contained in:
@@ -65,14 +65,22 @@ public class LootTrackerController
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public void storeLootRecord(HttpServletRequest request, HttpServletResponse response, @RequestBody Collection<LootRecord> records) throws IOException
|
||||
{
|
||||
SessionEntry e = auth.handle(request, response);
|
||||
if (e == null)
|
||||
SessionEntry session = null;
|
||||
if (request.getHeader(RuneLiteAPI.RUNELITE_AUTH) != null)
|
||||
{
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||
return;
|
||||
session = auth.handle(request, response);
|
||||
if (session == null)
|
||||
{
|
||||
// error is set here on the response, so we shouldn't continue
|
||||
return;
|
||||
}
|
||||
}
|
||||
Integer userId = session == null ? null : session.getUser();
|
||||
|
||||
service.store(records, e.getUser());
|
||||
if (userId != null)
|
||||
{
|
||||
service.store(records, userId);
|
||||
}
|
||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||
|
||||
try (Jedis jedis = redisPool.getResource())
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.runelite.http.service.loottracker;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
@@ -91,7 +92,10 @@ public class LootTrackerControllerTest
|
||||
lootRecord.setDrops(Collections.singletonList(new GameItem(4151, 1)));
|
||||
|
||||
String data = RuneLiteAPI.GSON.toJson(Collections.singletonList(lootRecord));
|
||||
mockMvc.perform(post("/loottracker").content(data).contentType(MediaType.APPLICATION_JSON))
|
||||
mockMvc.perform(post("/loottracker")
|
||||
.header(RuneLiteAPI.RUNELITE_AUTH, UUID.nameUUIDFromBytes("test".getBytes()))
|
||||
.content(data)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
verify(lootTrackerService).store(eq(Collections.singletonList(lootRecord)), anyInt());
|
||||
|
||||
Reference in New Issue
Block a user