Skip to content

Commit

Permalink
chore: remove deprecated luminus functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Beebeeoii committed Aug 9, 2024
1 parent db058e1 commit 0989489
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 852 deletions.
33 changes: 2 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

# About <a name="about">

Lominus is a tool written in Go to automatically sync [Luminus](https://luminus.nus.edu.sg) and [Canvas](https://canvas.nus.edu.sg/) files onto your local storage for easy access to updated files. It runs on Windows, macOS and Linux.
Lominus is a tool written in Go to automatically sync [Canvas](https://canvas.nus.edu.sg/) files onto your local storage for easy access to updated files. It runs on Windows, macOS and Linux.

**No credentials, files, or any other form of information is uploaded to any servers. Everything is stored locally on your system. Credentials are only used for authentication.**

Expand Down Expand Up @@ -171,31 +171,6 @@ import (
"github.com/beebeeoii/lominus/pkg/constants"
)
func getLuminusModules() {
jwtToken, jwtTokenErr := auth.RetrieveJwtToken(auth.LuminusCredentials{
Username: "nusstu\\e0123456",
Password: "password",
}, false)
if jwtTokenErr != nil {
log.Fatalln(jwtTokenErr)
}
modulesReq, modReqErr := api.BuildModulesRequest(jwtToken, constants.Luminus)
if modReqErr != nil {
log.Fatalln(modReqErr)
}
modules, modulesErr := modulesReq.GetModules()
if modulesErr != nil {
log.Fatalln(modulesErr)
}
for _, module := range modules {
log.Println(module.ModuleCode, module.Name)
}
}
func getCanvasModules() {
canvasToken := "your-canvas-token"
Expand Down Expand Up @@ -261,10 +236,6 @@ Lominus is far from perfect. All contributions, regardless large or small, are h
# FAQ
1. I am unable to verify my Luminus login credentials.
- Please ensure that you have trusted the SSL Certificate used by Luminus, **especially on Unix systems**.
2. Will my annotated lecture notes be overwritten if there exists a newer version uploaded by the Professor?
1. Will my annotated lecture notes be overwritten if there exists a newer version uploaded by the Professor?
- Your annotated file will be renamed to `[v1] XXX.XXX` and the newer version will be downloaded.
7 changes: 0 additions & 7 deletions internal/constants/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ const (
// Credentials Tab
CREDENTIALS_TITLE = "Credentials"

LUMINUS_TAB_TITLE = "Luminus"
LUMINUS_TAB_DESCRIPTION = `Credentials are saved **locally**. It is used for logging into [Luminus](https://luminus.nus.edu.sg) **only**.`
LUMINUS_USERNAME_TEXT = "Username"
LUMINUS_USERNAME_PLACEHOLDER = "Eg: nusstu\\e0123456"
LUMINUS_PASSWORD_TEXT = "Password"
LUMINUS_PASSWORD_PLACEHOLDER = "Password"

CANVAS_TAB_TITLE = "Canvas"
CANVAS_TAB_DESCRIPTION = `Token is saved **locally**. It is used to access [Canvas](https://canvas.nus.edu.sg/) **only**.`
CANVAS_TOKEN_TEXT = "Canvas Token"
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func BuildSystemTray() *fyne.Menu {
}

if pref.Directory == "" {
notifications.NotificationChannel <- notifications.Notification{Title: "Unable to sync", Content: "Please set the directory to store your Luminus files"}
notifications.NotificationChannel <- notifications.Notification{Title: "Unable to sync", Content: "Please set the directory to store your files"}
return
}

Expand Down
123 changes: 1 addition & 122 deletions pkg/api/files.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package api provides functions that link up and communicate with LMS servers,
// such as Canvas and Luminus (probably removed in near future).
// such as Canvas.
package api

import (
Expand All @@ -10,14 +10,12 @@ import (
"net/url"
"os"
"path/filepath"
"reflect"
"strconv"
"time"

appFile "github.com/beebeeoii/lominus/internal/file"
"github.com/beebeeoii/lominus/pkg/constants"
"github.com/beebeeoii/lominus/pkg/interfaces"
"github.com/mitchellh/mapstructure"
)

// Folder struct is the datapack for containing details about a Folder.
Expand Down Expand Up @@ -45,10 +43,6 @@ type File struct {
DownloadUrl string
}

const FOLDER_URL_ENDPOINT = "https://luminus.nus.edu.sg/v2/api/files/?populate=totalFileCount,subFolderCount,TotalSize&ParentID=%s"
const FILE_URL_ENDPOINT = "https://luminus.nus.edu.sg/v2/api/files/%s/file?populate=Creator,lastUpdatedUser,comment"
const DOWNLOAD_URL_ENDPOINT = "https://luminus.nus.edu.sg/v2/api/files/file/%s/downloadurl"

func (moduleFolderRequest ModuleFolderRequest) GetModuleFolder() (Folder, error) {
folder := Folder{}

Expand Down Expand Up @@ -154,42 +148,6 @@ func (foldersRequest FoldersRequest) GetFolders() ([]Folder, error) {

folders = append(folders, nextFolders...)
}
case constants.Luminus:
foldersData := []interfaces.LuminusFolderObject{}

response := interfaces.LuminusRawResponse{}
reqErr := foldersRequest.Request.Send(&response)
if reqErr != nil {
return folders, reqErr
}

data := reflect.ValueOf(response.Data)
if data.Kind() == reflect.Slice {
for i := 0; i < data.Len(); i++ {
folderData := interfaces.LuminusFolderObject{}
decodeErr := mapstructure.Decode(data.Index(i).Interface(), &folderData)
if decodeErr != nil {
return folders, decodeErr
}
foldersData = append(foldersData, folderData)
}
}

for _, folderObject := range foldersData {
// Folder is not available.
if reflect.ValueOf(folderObject.AccessObject).IsNil() {
continue
}

folders = append(folders, Folder{
Id: folderObject.Id,
Name: appFile.CleanseFolderFileName(folderObject.Name),
Downloadable: folderObject.IsActive && !folderObject.AllowUpload,
HasSubFolder: folderObject.FoldersCount > 0,
Ancestors: ancestors,
IsRootFolder: false,
})
}
default:
return folders, errors.New("foldersRequest.Request.Url.Platform is not available")
}
Expand All @@ -213,35 +171,6 @@ func (foldersRequest FoldersRequest) GetRootFiles() ([]File, error) {
if !builder.IsAccessible {
return files, nil
}

// Retrieving of folders in main folder is only required for Luminus
// as Canvas already returns its
if foldersRequest.Request.Url.Platform != constants.Luminus {
break
}

moduleMainFolder := Folder{
Id: builder.Id,
Name: appFile.CleanseFolderFileName(builder.Name),
Downloadable: true,
HasSubFolder: true, // doesn't matter
Ancestors: []string{}, // main folder does not have any ancestors
}
subFilesReq, subFilesReqErr := BuildFilesRequest(
foldersRequest.Request.Token,
foldersRequest.Request.Url.Platform,
moduleMainFolder,
)
if subFilesReqErr != nil {
return files, subFilesReqErr
}

subFiles, subFilesErr := subFilesReq.GetFiles()
if subFilesErr != nil {
return files, subFilesErr
}

files = append(files, subFiles...)
case Folder:
// Folder exists but its contents are restricted to be downloaded.
if !builder.Downloadable {
Expand Down Expand Up @@ -378,56 +307,6 @@ func (filesRequest FilesRequest) GetFiles() ([]File, error) {

files = append(files, nextFiles...)
}
case constants.Luminus:
filesData := []interfaces.LuminusFileObject{}

response := interfaces.LuminusRawResponse{}
reqErr := filesRequest.Request.Send(&response)
if reqErr != nil {
return files, reqErr
}

data := reflect.ValueOf(response.Data)
if data.Kind() == reflect.Slice {
for i := 0; i < data.Len(); i++ {
fileData := interfaces.LuminusFileObject{}
decodeErr := mapstructure.Decode(data.Index(i).Interface(), &fileData)
if decodeErr != nil {
return files, decodeErr
}
filesData = append(filesData, fileData)
}
}

for _, fileObject := range filesData {
lastUpdated, err := time.Parse(time.RFC3339, fileObject.LastUpdated)
if err != nil {
return files, err
}

downloadUrlResponse := LuminusDownloadResponse{}
downloadRequest := Request{
Method: GET_METHOD,
Token: filesRequest.Request.Token,
UserAgent: filesRequest.Request.UserAgent,
Url: interfaces.Url{
Url: fmt.Sprintf(DOWNLOAD_URL_ENDPOINT, fileObject.Id),
Platform: filesRequest.Request.Url.Platform,
},
}
downloadUrlResponseErr := downloadRequest.GetRawResponse(&downloadUrlResponse)
if downloadUrlResponseErr != nil {
return files, downloadUrlResponseErr
}

files = append(files, File{
Id: fileObject.Id,
Name: appFile.CleanseFolderFileName(fileObject.Name),
LastUpdated: lastUpdated,
Ancestors: ancestors,
DownloadUrl: downloadUrlResponse.DownloadUrl,
})
}
default:
return files, errors.New("filesRequest.Request.Url.Platform is not available")
}
Expand Down
36 changes: 1 addition & 35 deletions pkg/api/modules.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Package api provides functions that link up and communicate with LMS servers,
// such as Canvas and Luminus (probably removed in near future).
// such as Canvas.
package api

import (
"errors"
"reflect"
"strconv"
"strings"

"github.com/beebeeoii/lominus/pkg/constants"
"github.com/beebeeoii/lominus/pkg/interfaces"
"github.com/mitchellh/mapstructure"
)

// Module struct is the datapack for containing details about every module
Expand All @@ -21,8 +19,6 @@ type Module struct {
IsAccessible bool
}

const MODULE_URL_ENDPOINT = "https://luminus.nus.edu.sg/v2/api/module/?populate=Creator,termDetail,isMandatory"

// GetModules retrieves all the modules being taken by the user on the specified LMS
// via a ModulesRequest.
func (modulesRequest ModulesRequest) GetModules() ([]Module, error) {
Expand All @@ -48,36 +44,6 @@ func (modulesRequest ModulesRequest) GetModules() ([]Module, error) {
IsAccessible: !moduleObject.IsAccessRestrictedByDate,
})
}
case constants.Luminus:
modulesData := []interfaces.LuminusModuleObject{}

response := interfaces.LuminusRawResponse{}
reqErr := modulesRequest.Request.Send(&response)

if reqErr != nil {
return modules, reqErr
}

data := reflect.ValueOf(response.Data)
if data.Kind() == reflect.Slice {
for i := 0; i < data.Len(); i++ {
moduleData := interfaces.LuminusModuleObject{}
decodeErr := mapstructure.Decode(data.Index(i).Interface(), &moduleData)
if decodeErr != nil {
return modules, decodeErr
}
modulesData = append(modulesData, moduleData)
}
}

for _, moduleObject := range modulesData {
modules = append(modules, Module{
Id: moduleObject.Id,
Name: moduleObject.Name,
ModuleCode: cleanseModuleCode(moduleObject.ModuleCode),
IsAccessible: moduleObject.IsCourseSearchable && moduleObject.IsPublished,
})
}
default:
return modules, errors.New("modulesRequest.Request.Url.Platform is not available")
}
Expand Down
Loading

0 comments on commit 0989489

Please sign in to comment.