-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added compability api for
StreamCompanion
- Loading branch information
Showing
13 changed files
with
623 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { HttpServer, sendJson } from '../index'; | ||
import { beatmapFileShortcut } from '../scripts/beatmapFile'; | ||
|
||
export default function buildSCApi(app: HttpServer) { | ||
app.route('/json/sc', 'GET', (req, res) => { | ||
const osuInstance: any = req.instanceManager.getInstance(); | ||
if (!osuInstance) { | ||
res.statusCode = 500; | ||
return sendJson(res, { error: 'not_ready' }); | ||
} | ||
|
||
const json = osuInstance.getStateSC(req.instanceManager); | ||
sendJson(res, json); | ||
}); | ||
|
||
app.route('/backgroundImage', 'GET', (req, res) => | ||
beatmapFileShortcut(req, res, 'background') | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { wLogger } from '@tosu/common'; | ||
import { ServerResponse } from 'http'; | ||
import path from 'path'; | ||
|
||
import { directoryWalker } from '../utils/directories'; | ||
import { ExtendedIncomingMessage } from '../utils/http'; | ||
import { sendJson } from '../utils/index'; | ||
|
||
export function beatmapFileShortcut( | ||
req: ExtendedIncomingMessage, | ||
res: ServerResponse, | ||
beatmapFileType: 'audio' | 'background' | 'file' | ||
) { | ||
try { | ||
const url = req.pathname || '/'; | ||
|
||
const osuInstance: any = req.instanceManager.getInstance(); | ||
if (!osuInstance) { | ||
res.statusCode = 500; | ||
return sendJson(res, { error: 'not_ready' }); | ||
} | ||
|
||
const { global, menu } = osuInstance.getServices(['global', 'menu']); | ||
if ( | ||
(global.gameFolder === '' && global.skinFolder === '') || | ||
(global.gameFolder == null && global.skinFolder == null) | ||
) { | ||
res.statusCode = 500; | ||
return sendJson(res, { error: 'not_ready' }); | ||
} | ||
|
||
const folder = path.join(global.songsFolder, menu.folder || ''); | ||
let fileName = ''; | ||
|
||
if (beatmapFileType === 'audio') fileName = menu.audioFilename; | ||
else if (beatmapFileType === 'background') | ||
fileName = menu.backgroundFilename; | ||
else if (beatmapFileType === 'file') fileName = menu.filename; | ||
else { | ||
return sendJson(res, { | ||
error: 'Unknown file type' | ||
}); | ||
} | ||
|
||
directoryWalker({ | ||
res, | ||
baseUrl: url, | ||
pathname: fileName || '', | ||
folderPath: folder | ||
}); | ||
} catch (error) { | ||
wLogger.error((error as any).message); | ||
wLogger.debug(error); | ||
|
||
return sendJson(res, { | ||
error: (error as any).message | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
export type ApiAnswer = scAPI | { error?: string }; | ||
|
||
export interface scAPI { | ||
sliders: number; | ||
mMaxBpm: number; | ||
banchoUsername: string; | ||
banchoId: number; | ||
ppIfMapEndsNow: number; | ||
mapKiaiPoints: { | ||
startTime: number; | ||
duration: number; | ||
}[]; | ||
strainPpIfMapEndsNow: number; | ||
titleRoman: string; | ||
retries: number; | ||
status: number; | ||
osu_99PP: number; | ||
maxBpm: number; | ||
skinPath: string; | ||
spinners: number; | ||
rankedStatus: number; | ||
source: string; | ||
aimPpIfMapEndsNow: number; | ||
backgroundImageFileName: string; | ||
songSelectionRankingType: number; | ||
acc: number; | ||
mStars: number; | ||
mapStrains: { [key: string]: number }; | ||
miss: number; | ||
timeLeft: string; | ||
playerHpSmooth: number; | ||
hitErrors: number[]; | ||
sv: number; | ||
mapArtistTitleUnicode: string; | ||
banchoIsConnected: number; | ||
keyOverlay: string; | ||
mMinBpm: number; | ||
mBpm: string; | ||
simulatedPp: number; | ||
sliderBreaks: number; | ||
osu_m98PP: number; | ||
mapBreaks: { | ||
startTime: number; | ||
endTime: number; | ||
hasEffect: boolean; | ||
}[]; | ||
tags: string; | ||
unstableRate: number; | ||
leaderBoardMainPlayer: string; | ||
banchoCountry: string; | ||
comboLeft: number; | ||
currentMaxCombo: number; | ||
osu_m97PP: number; | ||
md5: string; | ||
artistUnicode: string; | ||
osu_m96PP: number; | ||
osu_m90PP: number; | ||
osu_SSPP: number; | ||
osuIsRunning: number; | ||
banchoStatus: number; | ||
isBreakTime: number; | ||
maxCombo: number; | ||
mode: number; | ||
previewtime: number; | ||
mAR: number; | ||
plays: number; | ||
osu_m95PP: number; | ||
accPpIfMapEndsNow: number; | ||
mapArtistTitle: string; | ||
songSelectionScores: string; | ||
geki: number; | ||
osu_98PP: number; | ||
modsEnum: number; | ||
diffName: string; | ||
firstHitObjectTime: number; | ||
songSelectionMainPlayerScore: string; | ||
username: string; | ||
speedPpIfMapEndsNow: number; | ||
hp: number; | ||
creator: string; | ||
c50: number; | ||
mania_m1_000_000PP: number; | ||
liveStarRating: number; | ||
artistRoman: string; | ||
totalAudioTime: number; | ||
ppIfRestFced: number; | ||
mp3Name: string; | ||
osu_97PP: number; | ||
skin: string; | ||
osu_95PP: number; | ||
cs: number; | ||
osu_mSSPP: number; | ||
localTime: number; | ||
mods: string; | ||
bpm: number; | ||
circles: number; | ||
drainingtime: number; | ||
playerHp: number; | ||
test: string; | ||
mapsetid: number; | ||
osuFileName: string; | ||
noChokePp: number; | ||
threadid: number; | ||
katsu: number; | ||
osu_90PP: number; | ||
mOD: number; | ||
maxGrade: number; | ||
localTimeISO: string; | ||
c100: number; | ||
leaderBoardPlayers: string; | ||
mapTimingPoints: { | ||
startTime: number; | ||
bpm?: number; | ||
beatLength: number; | ||
}[]; | ||
osu_99_9PP: number; | ||
titleUnicode: string; | ||
osuFileLocation: string; | ||
ar: number; | ||
mania_1_000_000PP: number; | ||
totaltime: number; | ||
mHP: number; | ||
songSelectionTotalScores: number; | ||
dl: string; | ||
mapid: number; | ||
minBpm: number; | ||
score: number; | ||
sl: number; | ||
convertedUnstableRate: number; | ||
mapDiff: string; | ||
ingameInterfaceIsEnabled: number; | ||
mCS: number; | ||
time: number; | ||
rawStatus: number; | ||
dir: string; | ||
c300: number; | ||
mainBpm: number; | ||
osu_m99PP: number; | ||
currentBpm: number; | ||
osu_96PP: number; | ||
combo: number; | ||
mMainBpm: number; | ||
grade: number; | ||
gameMode: string; | ||
chatIsEnabled: number; | ||
mapPosition: string; | ||
backgroundImageLocation: string; | ||
starsNomod: number; | ||
od: number; | ||
osu_m99_9PP: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.